Package org.eclipse.jetty.util
Class Promise.Task<T>
java.lang.Object
org.eclipse.jetty.util.Promise.Task<T>
- Type Parameters:
T
- the type of the result of the task
A Promise
that implements Runnable
to perform
a one-shot task that eventually completes this Promise
.
Subclasses override Runnable.run()
to implement the task.
Users of this class start the task execution via Runnable.run()
.
Typical usage:
// Specify what to do in case of success and failure.
Promise.Task<T> task = new Promise.Task<>(() -> onSuccess(), x -> onFailure(x))
{
@Override
public void run()
{
try
{
// Perform some task.
T result = performTask();
// Eventually succeed this Promise.
succeeded(result);
}
catch (Throwable x)
{
// Fail this Promise.
failed(x);
}
}
}
// Start the task.
task.run();
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Promise
Promise.Adapter<U>, Promise.Completable<S>, Promise.Invocable<R>, Promise.Task<T>, Promise.Wrapper<W>
-
Field Summary
-
Constructor Summary
-
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Promise
completeWith
-
Constructor Details
-
Task
public Task() -
Task
-
-
Method Details