- 所有超级接口:
Future<T>,ICompletionStage<T>
- 所有已知子接口:
IPromise<T>,IScheduledFuture<V>,IScheduledPromise<V>
ps:一定要阅读ICompletionStage中关于上下文和线程控制的说明、
- 作者:
- wjybxx date - 2023/11/6
-
嵌套类概要
从接口继承的嵌套类/接口 java.util.concurrent.Future
Future.State -
方法概要
修饰符和类型方法说明返回只读的Future视图, 如果Future是一个提供了写接口的Promise,则返回一个只读的Future视图,返回的实例会在当前Promise进入完成状态时进入完成状态。await()阻塞到任务完成boolean阻塞到任务完成booleanawaitUninterruptibly(long timeout, TimeUnit unit) booleancancel(boolean mayInterruptIfRunning) 已过时。catching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback) catching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback, IContext ctx, int options) 它表示能从从特定的异常中恢复,并返回一个正常结果。catchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback) catchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback, IContext ctx, int options) <U> IFuture<U> composeApply(BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeApply(BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn, IContext ctx, int options) 该方法表示在当前Future与返回的Future中插入一个异步操作,构建异步管道 => 这是链式调用的核心API。<U> IFuture<U> composeApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn, IContext ctx, int options) <U> IFuture<U> composeCall(Function<? super IContext, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeCall(Function<? super IContext, ? extends ICompletionStage<U>> fn, IContext ctx, int options) <U> IFuture<U> composeCallAsync(Executor executor, Function<? super IContext, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeCallAsync(Executor executor, Function<? super IContext, ? extends ICompletionStage<U>> fn, IContext ctx, int options) composeCatching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback) composeCatching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback, IContext ctx, int options) 它表示能从从特定的异常中恢复,并异步返回一个正常结果。composeCatchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback) composeCatchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback, IContext ctx, int options) <U> IFuture<U> composeHandle(TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeHandle(TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn, IContext ctx, int options) 它表示既能接收任务的正常结果,也可以接收任务异常结果,并异步返回一个运算结果。<U> IFuture<U> composeHandleAsync(Executor executor, TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn) <U> IFuture<U> composeHandleAsync(Executor executor, TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn, IContext ctx, int options) default Throwable非阻塞方式获取导致Future失败的原因,不适用被取消的Future; 如果需要获取取消异常,可使用exceptionNow(boolean)。exceptionNow(boolean throwIfCancelled) 获取导致任务失败的异常,可获取取消异常get()default TgetNow()获取关联的计算结果 -- 非阻塞。尝试获取计算结果 -- 非阻塞 如果对应的计算失败,则抛出对应的异常。<U> IFuture<U> handle(TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn) <U> IFuture<U> 该方法表示既能处理当前计算的正常结果,又能处理当前结算的异常结果(可以将异常转换为新的结果),并返回一个新的结果。<U> IFuture<U> handleAsync(Executor executor, TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn) <U> IFuture<U> handleAsync(Executor executor, TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn, IContext ctx, int options) default boolean如果future关联的任务在正常完成被取消,则返回true。default boolean如果future关联的任务正在执行中,则返回truedefault booleanisDone()如果future已进入完成状态(成功、失败、被取消),则返回truedefault booleanisFailed()如果future已进入完成状态,且是失败状态,则返回truedefault boolean在JDK的约定中,取消和failed是分离的,我们仍保持这样的约定; 但有些时候,我们需要将取消也视为失败的一种,因此需要快捷的方法。default boolean如果future关联的任务仍处于等待执行的状态,则返回true (换句话说,如果任务仍在排队,则返回true)default boolean如果future已进入完成状态,且是成功完成,则返回true。join()阻塞到任务完成voidonCompleted(BiConsumer<? super IFuture<T>, ? super IContext> action, IContext context) voidonCompleted(BiConsumer<? super IFuture<T>, ? super IContext> action, IContext context, int options) 该接口支持Context参数,可响应取消voidonCompleted(Consumer<? super IFuture<T>> action) voidonCompleted(Consumer<? super IFuture<T>> action, int options) 最原始的Future监听接口 1.voidonCompletedAsync(Executor executor, BiConsumer<? super IFuture<T>, ? super IContext> action, IContext context) voidonCompletedAsync(Executor executor, BiConsumer<? super IFuture<T>, ? super IContext> action, IContext context, int options) voidonCompletedAsync(Executor executor, Consumer<? super IFuture<T>> action) voidonCompletedAsync(Executor executor, Consumer<? super IFuture<T>> action, int options) 非阻塞方式获取Future的执行结果state()已过时。status()future关联的任务的状态thenAccept(BiConsumer<? super IContext, ? super T> action) thenAccept(BiConsumer<? super IContext, ? super T> action, IContext ctx, int options) 该方法返回一个新的Future,它的结果由当前Future驱动。thenAcceptAsync(Executor executor, BiConsumer<? super IContext, ? super T> action) thenAcceptAsync(Executor executor, BiConsumer<? super IContext, ? super T> action, IContext ctx, int options) <U> IFuture<U> thenApply(BiFunction<? super IContext, ? super T, ? extends U> fn) <U> IFuture<U> thenApply(BiFunction<? super IContext, ? super T, ? extends U> fn, IContext ctx, int options) 该方法返回一个新的Future,它的结果由当前Future驱动。<U> IFuture<U> thenApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends U> fn) <U> IFuture<U> thenApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends U> fn, IContext ctx, int options) <U> IFuture<U> <U> IFuture<U> 该方法返回一个新的Future,它的结果由当前Future驱动。<U> IFuture<U> thenCallAsync(Executor executor, Function<? super IContext, ? extends U> fn) <U> IFuture<U> thenCallAsync(Executor executor, Function<? super IContext, ? extends U> fn, IContext ctx, int options) 该方法返回一个新的Future,它的结果由当前Future驱动。thenRunAsync(Executor executor, Consumer<? super IContext> action) thenRunAsync(Executor executor, Consumer<? super IContext> action, IContext ctx, int options) whenComplete(TriConsumer<? super IContext, ? super T, ? super Throwable> action) whenComplete(TriConsumer<? super IContext, ? super T, ? super Throwable> action, IContext ctx, int options) 该方法返回一个新的Future,无论当前Future执行成功还是失败,给定的操作都将执行,且返回的Future始终以相同的结果进入完成状态。whenCompleteAsync(Executor executor, TriConsumer<? super IContext, ? super T, ? super Throwable> action) whenCompleteAsync(Executor executor, TriConsumer<? super IContext, ? super T, ? super Throwable> action, IContext ctx, int options) 从接口继承的方法 cn.wjybxx.concurrent.ICompletionStage
executor, toCompletableFuture, toFuture
-
方法详细资料
-
asReadonly
返回只读的Future视图, 如果Future是一个提供了写接口的Promise,则返回一个只读的Future视图,返回的实例会在当前Promise进入完成状态时进入完成状态。1. 一般情况下我们通过接口隔离即可达到读写分离目的,这可以节省开销;在大规模链式调用的情况下,Promise继承Future很有效。 2. 但如果觉得返回Promise实例给任务的发起者不够安全,可创建Promise的只读视图返回给用户 3. 这里不要求返回的必须是同一个实例,每次都可以创建一个新的实例。
-
cancel
已过时。通过ctx中的ICancelToken发起取消请求,该方法仅用于和旧代码和外部库交互。 -
state
已过时。 -
status
TaskStatus status()future关联的任务的状态 -
isPending
default boolean isPending()如果future关联的任务仍处于等待执行的状态,则返回true (换句话说,如果任务仍在排队,则返回true) -
isComputing
default boolean isComputing()如果future关联的任务正在执行中,则返回true -
isSucceeded
default boolean isSucceeded()如果future已进入完成状态,且是成功完成,则返回true。 -
isFailed
default boolean isFailed()如果future已进入完成状态,且是失败状态,则返回true -
isCancelled
default boolean isCancelled()如果future关联的任务在正常完成被取消,则返回true。- 指定者:
isCancelled在接口中Future<T>
-
isDone
default boolean isDone()如果future已进入完成状态(成功、失败、被取消),则返回true -
isFailedOrCancelled
default boolean isFailedOrCancelled()在JDK的约定中,取消和failed是分离的,我们仍保持这样的约定; 但有些时候,我们需要将取消也视为失败的一种,因此需要快捷的方法。 -
getNow
获取关联的计算结果 -- 非阻塞。 如果对应的计算失败,则抛出对应的异常。 如果计算成功,则返回计算结果。 如果计算尚未完成,则返回null。如果future关联的task没有返回值(操作完成返回null),对于这种情况,你可以使用
isSucceeded()作为判断任务是否成功执行的更好选择。- 抛出:
CompletionException- 计算失败CancellationException- 被取消
-
getNow
尝试获取计算结果 -- 非阻塞 如果对应的计算失败,则抛出对应的异常。 如果计算成功,则返回计算结果。 如果计算尚未完成,则返回给定值。- 参数:
valueIfAbsent- 计算尚未完成时的返回值- 抛出:
CompletionException- 计算失败CancellationException- 被取消
-
resultNow
T resultNow()非阻塞方式获取Future的执行结果- 指定者:
resultNow在接口中Future<T>- 抛出:
IllegalStateException- 如果任务不是成功完成状态
-
exceptionNow
非阻塞方式获取导致Future失败的原因,不适用被取消的Future; 如果需要获取取消异常,可使用exceptionNow(boolean)。- 指定者:
exceptionNow在接口中Future<T>- 抛出:
IllegalStateException- 如果任务不是失败完成状态
-
exceptionNow
获取导致任务失败的异常,可获取取消异常- 参数:
throwIfCancelled- 任务取消的状态下是否抛出状态异常- 抛出:
IllegalStateException- 如果任务不是失败完成状态
-
get
- 指定者:
get在接口中Future<T>- 抛出:
InterruptedExceptionExecutionException
-
get
T get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - 指定者:
get在接口中Future<T>- 抛出:
InterruptedExceptionExecutionExceptionTimeoutException
-
join
T join()阻塞到任务完成- 抛出:
CompletionException- 计算失败CancellationException- 被取消
-
await
阻塞到任务完成- 返回:
- this
- 抛出:
InterruptedException
-
awaitUninterruptibly
阻塞到任务完成- 返回:
- this
-
await
- 返回:
- 如果任务在这期间进入了完成状态,则返回true
- 抛出:
InterruptedException
-
awaitUninterruptibly
- 返回:
- 如果任务在这期间进入了完成状态,则返回true
-
onCompleted
最原始的Future监听接口 1. 给定的Action将在Future关联的任务完成时执行,无论成功或失败都将执行。 2. 该操作不是链式调用,不会继承上下文!不会继承上下文!不会继承上下文! 3. 通常只用于一些特殊功能 -- 比如大规模监听时减少开销。 4. 暂不设定返回会为this,以免以后需要封装用于删除的句柄等- 参数:
options- 调度选项,可为0
-
onCompleted
-
onCompletedAsync
-
onCompletedAsync
-
onCompleted
void onCompleted(BiConsumer<? super IFuture<T>, ? super IContext> action, @Nonnull IContext context, int options) 该接口支持Context参数,可响应取消 -
onCompleted
-
onCompletedAsync
-
onCompletedAsync
-
composeApply
<U> IFuture<U> composeApply(BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法表示在当前Future与返回的Future中插入一个异步操作,构建异步管道 => 这是链式调用的核心API。 该方法对应我们日常流中使用的Stream.flatMap(Function)操作。该方法返回一个新的
Future,它的最终结果与指定的Function返回的Future结果相同。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则当前Future的执行结果将作为指定操作的执行参数。- 指定者:
composeApply在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
composeApply
<U> IFuture<U> composeApply(BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn) - 指定者:
composeApply在接口中ICompletionStage<T>- 参数:
fn- 的ctx参数为IContext.NONE
-
composeApplyAsync
<U> IFuture<U> composeApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn) - 指定者:
composeApplyAsync在接口中ICompletionStage<T>
-
composeApplyAsync
<U> IFuture<U> composeApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) - 指定者:
composeApplyAsync在接口中ICompletionStage<T>
-
composeCall
<U> IFuture<U> composeCall(Function<? super IContext, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法表示在当前Future与返回的Future中插入一个异步操作,构建异步管道 该方法对应我们日常流中使用的Stream.flatMap(Function)操作。该方法返回一个新的
Future,它的最终结果与指定的Function返回的Future结果相同。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则当前Future的执行结果将作为指定操作的执行参数。CompletionStage.thenCompose(Function)ICompletionStage.composeApply(BiFunction)- 指定者:
composeCall在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
composeCall
- 指定者:
composeCall在接口中ICompletionStage<T>
-
composeCallAsync
<U> IFuture<U> composeCallAsync(Executor executor, Function<? super IContext, ? extends ICompletionStage<U>> fn) - 指定者:
composeCallAsync在接口中ICompletionStage<T>
-
composeCallAsync
<U> IFuture<U> composeCallAsync(Executor executor, Function<? super IContext, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) - 指定者:
composeCallAsync在接口中ICompletionStage<T>
-
composeCatching
<X extends Throwable> IFuture<T> composeCatching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage它表示能从从特定的异常中恢复,并异步返回一个正常结果。该方法返回一个新的
Future,它的结果由当前Future驱动。 如果当前Future正常完成,则给定的动作不会执行,且返回的Future使用相同的结果值进入完成状态。 如果当前Future执行失败,则其异常信息将作为指定操作的执行参数,返回的Future的结果取决于指定操作的执行结果。- 指定者:
composeCatching在接口中ICompletionStage<T>- 参数:
fallback- 恢复函数ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
composeCatching
<X extends Throwable> IFuture<T> composeCatching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback) - 指定者:
composeCatching在接口中ICompletionStage<T>
-
composeCatchingAsync
<X extends Throwable> IFuture<T> composeCatchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback) - 指定者:
composeCatchingAsync在接口中ICompletionStage<T>
-
composeCatchingAsync
<X extends Throwable> IFuture<T> composeCatchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends ICompletionStage<T>> fallback, @Nullable IContext ctx, int options) - 指定者:
composeCatchingAsync在接口中ICompletionStage<T>
-
composeHandle
<U> IFuture<U> composeHandle(TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage它表示既能接收任务的正常结果,也可以接收任务异常结果,并异步返回一个运算结果。该方法返回一个新的
Future,它的结果由当前Future驱动。 不论当前Future成功还是失败,都将执行给定的操作,返回的Future的结果取决于指定操作的执行结果。- 指定者:
composeHandle在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
composeHandle
<U> IFuture<U> composeHandle(TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn) - 指定者:
composeHandle在接口中ICompletionStage<T>
-
composeHandleAsync
<U> IFuture<U> composeHandleAsync(Executor executor, TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn) - 指定者:
composeHandleAsync在接口中ICompletionStage<T>
-
composeHandleAsync
<U> IFuture<U> composeHandleAsync(Executor executor, TriFunction<? super IContext, ? super T, ? super Throwable, ? extends ICompletionStage<U>> fn, @Nullable IContext ctx, int options) - 指定者:
composeHandleAsync在接口中ICompletionStage<T>
-
thenApply
<U> IFuture<U> thenApply(BiFunction<? super IContext, ? super T, ? extends U> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法返回一个新的Future,它的结果由当前Future驱动。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则当前Future的执行结果将作为指定操作的执行参数,返回的Future的结果取决于指定操作的执行结果。- 指定者:
thenApply在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
thenApply
- 指定者:
thenApply在接口中ICompletionStage<T>
-
thenApplyAsync
<U> IFuture<U> thenApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends U> fn) - 指定者:
thenApplyAsync在接口中ICompletionStage<T>
-
thenApplyAsync
<U> IFuture<U> thenApplyAsync(Executor executor, BiFunction<? super IContext, ? super T, ? extends U> fn, @Nullable IContext ctx, int options) - 指定者:
thenApplyAsync在接口中ICompletionStage<T>
-
thenAccept
IFuture<Void> thenAccept(BiConsumer<? super IContext, ? super T> action, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法返回一个新的Future,它的结果由当前Future驱动。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则当前Future的执行结果将作为指定操作的执行参数,返回的Future的结果取决于指定操作的执行结果。- 指定者:
thenAccept在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
thenAccept
- 指定者:
thenAccept在接口中ICompletionStage<T>
-
thenAcceptAsync
- 指定者:
thenAcceptAsync在接口中ICompletionStage<T>
-
thenAcceptAsync
IFuture<Void> thenAcceptAsync(Executor executor, BiConsumer<? super IContext, ? super T> action, @Nullable IContext ctx, int options) - 指定者:
thenAcceptAsync在接口中ICompletionStage<T>
-
thenCall
<U> IFuture<U> thenCall(Function<? super IContext, ? extends U> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法返回一个新的Future,它的结果由当前Future驱动。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则执行给定的操作,返回的Future的结果取决于指定操作的执行结果。- 指定者:
thenCall在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
thenCall
- 指定者:
thenCall在接口中ICompletionStage<T>
-
thenCallAsync
- 指定者:
thenCallAsync在接口中ICompletionStage<T>
-
thenCallAsync
<U> IFuture<U> thenCallAsync(Executor executor, Function<? super IContext, ? extends U> fn, @Nullable IContext ctx, int options) - 指定者:
thenCallAsync在接口中ICompletionStage<T>
-
thenRun
从接口复制的说明:ICompletionStage该方法返回一个新的Future,它的结果由当前Future驱动。 如果当前Future执行失败,则返回的Future将以相同的原因失败,且指定的动作不会执行。 如果当前Future执行成功,则执行给定的操作,返回的Future的结果取决于指定操作的执行结果。- 指定者:
thenRun在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
thenRun
- 指定者:
thenRun在接口中ICompletionStage<T>
-
thenRunAsync
- 指定者:
thenRunAsync在接口中ICompletionStage<T>
-
thenRunAsync
IFuture<Void> thenRunAsync(Executor executor, Consumer<? super IContext> action, @Nullable IContext ctx, int options) - 指定者:
thenRunAsync在接口中ICompletionStage<T>
-
catching
<X extends Throwable> IFuture<T> catching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage它表示能从从特定的异常中恢复,并返回一个正常结果。该方法返回一个新的
Future,它的结果由当前Future驱动。 如果当前Future正常完成,则给定的动作不会执行,且返回的Future使用相同的结果值进入完成状态。 如果当前Future执行失败,则其异常信息将作为指定操作的执行参数,返回的Future的结果取决于指定操作的执行结果。不得不说JDK的
CompletionStage.exceptionally(Function)这个名字太差劲了,实现的也不够好,因此我们不使用它, 这里选择了Guava中的实现- 指定者:
catching在接口中ICompletionStage<T>- 参数:
exceptionType- 能处理的异常类型fallback- 异常恢复函数ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
catching
<X extends Throwable> IFuture<T> catching(Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback) - 指定者:
catching在接口中ICompletionStage<T>
-
catchingAsync
<X extends Throwable> IFuture<T> catchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback) - 指定者:
catchingAsync在接口中ICompletionStage<T>
-
catchingAsync
<X extends Throwable> IFuture<T> catchingAsync(Executor executor, Class<X> exceptionType, BiFunction<? super IContext, ? super X, ? extends T> fallback, @Nullable IContext ctx, int options) - 指定者:
catchingAsync在接口中ICompletionStage<T>
-
handle
<U> IFuture<U> handle(TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法表示既能处理当前计算的正常结果,又能处理当前结算的异常结果(可以将异常转换为新的结果),并返回一个新的结果。该方法返回一个新的
Future,无论当前Future执行成功还是失败,给定的操作都将执行。 如果当前Future执行成功,而指定的动作出现异常,则返回的Future以该异常完成。 如果当前Future执行失败,且指定的动作出现异常,则返回的Future以新抛出的异常进入完成状态。- 指定者:
handle在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
handle
- 指定者:
handle在接口中ICompletionStage<T>
-
handleAsync
<U> IFuture<U> handleAsync(Executor executor, TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn) - 指定者:
handleAsync在接口中ICompletionStage<T>
-
handleAsync
<U> IFuture<U> handleAsync(Executor executor, TriFunction<? super IContext, ? super T, Throwable, ? extends U> fn, @Nullable IContext ctx, int options) - 指定者:
handleAsync在接口中ICompletionStage<T>
-
whenComplete
IFuture<T> whenComplete(TriConsumer<? super IContext, ? super T, ? super Throwable> action, @Nullable IContext ctx, int options) 从接口复制的说明:ICompletionStage该方法返回一个新的Future,无论当前Future执行成功还是失败,给定的操作都将执行,且返回的Future始终以相同的结果进入完成状态。 与方法ICompletionStage.handle(TriFunction)不同,此方法不是为转换完成结果而设计的,因此提供的操作不应引发异常。
1.如果action出现了异常,则仅仅记录一个日志,不向下传播(这里与JDK实现不同) -- 应当避免抛出异常。 2.如果用户主动取消了返回的Future,或者用于异步执行的Executor已关闭,则不会以相同的结果进入完成状态。- 指定者:
whenComplete在接口中ICompletionStage<T>- 参数:
ctx- 上下文,如果为null,则替换为NONEoptions- 调度选项,默认使用0即可,可参考TaskOption
-
whenComplete
- 指定者:
whenComplete在接口中ICompletionStage<T>
-
whenCompleteAsync
IFuture<T> whenCompleteAsync(Executor executor, TriConsumer<? super IContext, ? super T, ? super Throwable> action) - 指定者:
whenCompleteAsync在接口中ICompletionStage<T>
-
whenCompleteAsync
IFuture<T> whenCompleteAsync(Executor executor, TriConsumer<? super IContext, ? super T, ? super Throwable> action, @Nullable IContext ctx, int options) - 指定者:
whenCompleteAsync在接口中ICompletionStage<T>
-
ICancelToken发起取消请求,该方法仅用于和旧代码和外部库交互。