com.g2forge.alexandria.java.concurrent.Slot Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ax-java Show documentation
Show all versions of ax-java Show documentation
Standard Java library and the basis of the ${alexandria.name} project.
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;
}
}