SimpleReact: 基於Java 8簡單的FRP Fluent API

來源:互聯網
上載者:User

標籤:

SimpleReact來自AOL的一個小型的支援並發的庫包,其直接基於Java 8的CompletableFuture, JDK函數介面和Streams API構建,它的Fluent API能夠提供解決90%的Reactive使用情境,重要的是沒有帶入任何複雜性。可以實現Functional Reactive Programming範式(簡稱:FRP,函數式響應編程)

使用SimpleReact能夠方便擴充微服務,它能用於管理微服務的遠程調用,能夠應付高並發大型高效能平台的要求。

使用SimpleReact能夠建立非堵塞的微服務和REST用戶端。

SimpleReact啟動於Supplier數組,其主要產生其他函數需要響應的資料,每個supplier會傳遞給Executor執行,都是以單獨的線程執行方式。

List<CompletableFuture<Integer>> futures = new SimpleReact()            .<Integer> react(() -> 1, () -> 2, () -> 3)            .with(it -> it * 100);

在這個案例中,3個supplier產生三個數字,這些都能並行地執行,當它們完成每個數字以後將乘以100,這也是作為一個並行的單獨任務執行(由ForkJoinPool 或可配置的任務執行器),Simple React將立即返回Future對象集合列表,這些任務也將非同步執行,不會有任何堵塞。

new SimpleReact()            .<Integer> react(() -> 1, () -> 2, () -> 3)            .then(it -> it * 100)            .then(it -> "*" + it)


React then允許事件reactor能夠被串聯,不像"React with",只返回一個Future集合,React then是一個fluent介面,能夠返回React builder,允許以後的reactor能夠被加入串聯鏈條中,React then不會堵塞,React with能夠在React then以後調用,只要React then提供訪問完整的CompleteableFuture API,CompleteableFuture 能通過 SimpleReact.react(streamOfCompleteableFutures)被傳遞迴SimpleReact。

更多複雜應用案例可見

項目:aol/simple-react · GitHub



SimpleReact: 基於Java 8簡單的FRP Fluent API

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.