use of org.osgi.util.promise.Promise in project aries by apache.
the class PromiseImpl method delay.
@Override
public Promise<T> delay(final long milliseconds) {
final PromiseImpl<T> p = new PromiseImpl<T>();
then(new Success<T, T>() {
@Override
public Promise<T> call(final Promise<T> resolved) throws Exception {
ses.schedule(new Runnable() {
@Override
public void run() {
try {
p.resolve(resolved.getValue());
} catch (IllegalStateException ise) {
// Someone else resolved our promise?
} catch (Exception e) {
p.fail(e);
}
}
}, milliseconds, MILLISECONDS);
return null;
}
}, new Failure() {
@Override
public void fail(final Promise<?> resolved) throws Exception {
ses.schedule(new Runnable() {
@Override
public void run() {
try {
p.fail(resolved.getFailure());
} catch (Exception e) {
p.fail(e);
}
}
}, milliseconds, MILLISECONDS);
}
});
return p;
}
Aggregations