@Override public HttpClientSpec responseIntercept(Operation operation) { responseInterceptor = responseInterceptor.append(response -> operation.then()); return this; }
/** * Pauses this execution for the given duration. * <p> * Unlike {@link Thread#sleep(long)}, this method does not block the thread. * The thread will be relinquished for use by other executions. * <p> * The given block will be invoked after the duration has passed. * The duration must be non-negative. * * @param duration the duration this execution should sleep for * @param onWake the code to resume with upon awaking * @since 1.5 */ static void sleep(Duration duration, Block onWake) { sleep(duration).then(onWake); }
public static void exec(Block block) { op(block).then(); }
@Override public void onComplete() { Operation.noop().then(() -> { if (done.compareAndSet(false, true)) { outSubscriber.onComplete(); } }); } });
/** * Converts this promise to an operation, which is the return of {@code function}. * * @param function a function that returns an operation for the promised value * @return effectively the return of {@code function} * @since 1.6 */ default Operation flatOp(Function<? super T, ? extends Operation> function) { return operation(t -> function.apply(t).then()); }
/** * Starts the execution, and executes the given operation. * * @param operation the operation to execute * @since 1.4 */ @NonBlocking default void start(Operation operation) { start(e -> operation.then()); }
/** * Converts a {@link Operation} into a {@link Completable}. * <p> * The returned Completable emits nothing if it succeeds, and emits the error (i.e. via {@code onError()}) if it fails. */ public static Completable complete(Operation operation) { return Completable.create(subscriber -> operation.onError(subscriber::onError).then(subscriber::onComplete) ); }
private void finalizeResponse(Iterator<Action<? super Response>> finalizers, Runnable then) { if (finalizers.hasNext()) { finalizers .next() .curry(this) .map(Operation::of) .then(() -> finalizeResponse(finalizers, then) ); } else { finalizeResponse(then); } }
@Override public Promise<List<T>> yield() { List<T> results = new ArrayList<>(); return Promise.async(d -> forEach((i, r) -> results.add(r)) .onError(d::error) .then(() -> d.success(results)) ); }
@Override public Promise<List<T>> yield() { List<Promise<T>> promises = Lists.newArrayList(this.promises); if (promises.isEmpty()) { return Promise.value(Collections.emptyList()); } List<T> results = Types.cast(promises); return Promise.async(d -> forEach(results::set).onError(d::error).then(() -> d.success(results))); }
@NonBlocking default void then() { then(Block.noop()); }
return Flux.create(sink -> operation.onError(sink::error).then(sink::complete));
function.apply(value) .onError(down::error) .then(() -> down.success(value)
function.apply(value) .onError(down::error) .then(() -> down.success(value)); } else { down.success(value);
@Override public void execute(Chain chain) throws Exception { chain .path(ctx -> { MeetingService service = ctx.get(MeetingService.class); ctx .byMethod(method -> method .get(() -> service .getMeetings() .map(Jackson::json) .then(ctx::render) ) .post(() -> ctx .parse(Jackson.fromJson(Meeting.class)) .nextOp(service::addMeeting) .map(m -> "Added meeting for " + m.getOrganizer()) .then(ctx::render) ) ); }) .get(":id:\\d+/rate/:rating:[1-5]", ctx -> { MeetingService service = ctx.get(MeetingService.class); PathTokens pathTokens = ctx.getPathTokens(); service .rateMeeting(pathTokens.get("id"), pathTokens.get("rating")) .then(() -> ctx.redirect("/meeting")); }); } }