CompletableFuture的常用方法
CompletableFuture.supplyAsync()
.thenRun(Runnable run)
比如A执行完执行B,但是B是不需要A的返回值
.thenAccept(Consumer con)
比如A执行完执行B,B依赖A的返回值,但是任务B是无返回值
.thenApply(Function fun)
比如A执行完执行B,B需要A的结果,并且B也是有返回值得
.applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn)
第一个参数,再传入一个异步任务,如:CompletableFuture.supplyAsync
第二个参数,用于对比谁先返回结果,输入一个参数,返回一个参数,
功能:用于谁是第一个任务完成的,先返回给谁
.thenCombine(CompletionStage<? extends U> other,BiFunction<? super T,? super U,? extends V> fn)
和上面功能相差不多,是使用第一个返回值,和第二个返回值,进行计算