CompletableFuture详解~applyToEither
生活随笔
收集整理的這篇文章主要介紹了
CompletableFuture详解~applyToEither
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在兩個完成的階段其中之一上應(yīng)用函數(shù)
下面的例子創(chuàng)建了CompletableFuture, applyToEither處理兩個階段, 在其中之一上應(yīng)用函數(shù)(包保證哪一個被執(zhí)行)。本例中的兩個階段一個是應(yīng)用大寫轉(zhuǎn)換在原始的字符串上, 另一個階段是應(yīng)用小些轉(zhuǎn)換。
static void applyToEitherExample() {String original = "Message";CompletableFuture cf1 = CompletableFuture.completedFuture(original).thenApplyAsync(s -> delayedUpperCase(s));CompletableFuture cf2 = cf1.applyToEither(CompletableFuture.completedFuture(original).thenApplyAsync(s -> delayedLowerCase(s)),s -> s + " from applyToEither");assertTrue(cf2.join().endsWith(" from applyToEither")); }總結(jié)
以上是生活随笔為你收集整理的CompletableFuture详解~applyToEither的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一键解决 go get golang.o
- 下一篇: Mockito—参数匹配~任意