io.windmill.core.Promise Maven / Gradle / Ivy
package io.windmill.core;
import io.windmill.core.tasks.Task0;
public class Promise
{
protected final Future future;
protected final Task0 task;
public Promise(CPU cpu, Task0 task)
{
this(new Future<>(cpu), task);
}
public Promise(Future future, Task0 task)
{
this.future = future;
this.task = task;
}
public Future getFuture()
{
return future;
}
protected void fulfil()
{
future.checkState(Future.State.WAITING);
try
{
future.setValue(task.compute());
}
catch (Throwable o)
{
future.setFailure(o);
}
}
protected void scheduleFailure(Throwable e)
{
future.cpu.schedule(() -> {
future.checkState(Future.State.WAITING);
future.setFailure(e);
return null;
});
}
public void schedule()
{
future.cpu.schedule(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy