All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.g2forge.alexandria.java.concurrent.Slot Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
package com.g2forge.alexandria.java.concurrent;

import java.util.concurrent.CountDownLatch;

public class Slot implements ISlotPF {
	protected final IFuture future = new IFuture() {
		@Override
		public T get0() {
			try {
				latch.await();
			} catch (final InterruptedException exception) {
				Thread.currentThread().interrupt();
				throw new RuntimeInterruptedException(exception);
			}
			return value;
		}
	};

	protected final IPromise promise = new IPromise() {
		@Override
		public void invoke() {
			latch.countDown();
		}

		@Override
		public IPromise set0(final T value) {
			Slot.this.value = value;
			return this;
		}
	};

	protected final CountDownLatch latch = new CountDownLatch(1);

	protected T value;

	public Slot() {}

	@Override
	public IFuture getFuture() {
		return future;
	}

	@Override
	public IPromise getPromise() {
		return promise;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy