com.firefly.utils.concurrent.Promise Maven / Gradle / Ivy
package com.firefly.utils.concurrent;
/**
*
* A callback abstraction that handles completed/failed events of asynchronous
* operations.
*
*
* @param
* the type of the context object
*/
public interface Promise {
/**
*
* Callback invoked when the operation completes.
*
*
* @param result
* the context
* @see #failed(Throwable)
*/
public void succeeded(C result);
/**
*
* Callback invoked when the operation fails.
*
*
* @param x
* the reason for the operation failure
*/
public void failed(Throwable x);
/**
*
* Empty implementation of {@link Promise}.
*
*
* @param
* the type of the result
*/
public static class Adapter implements Promise {
@Override
public void succeeded(U result) {
}
@Override
public void failed(Throwable x) {
x.printStackTrace();
}
}
}