Coder Social home page Coder Social logo

foldright / cffu Goto Github PK

View Code? Open in Web Editor NEW
134.0 4.0 15.0 1.98 MB

🦝 Java CompletableFuture Fu(aka CF-Fu, pronounced "Shifu"), a tiny sidekick library to improve user experience and reduce misuse.

Home Page: https://github.com/foldright/cffu

License: Apache License 2.0

Java 69.93% Kotlin 28.98% Shell 1.09%
completable-future completablefuture concurrency java fu shifu cffu tiny sidekick kotlin

cffu's Issues

v1.0 project management

📚 Documentation

🦮 CompletableFuture Guide

  • design patterns of biz usage
  • best practice and traps
  • write English doc, and English first

see README.md

🎪 CompletableFuture Usage Showcase

see CompletableFutureUsageShowcaseTest.kt

🇨🇳 Translations

📦 Library

see

✨ Support the missing convenient new functions

  • new methods CffuFactory.cffuAllOf(...)(7acfa4d)
    with results version of CompletableFuture.allof
  • new methods CffuFactory.cffuAnyOf(...)(d9df93f)
    type safe version of CompletableFuture.anyOf Method
  • new methods Cffu.cffuCombine(...)
    same as CffuFactory.cffuAllOf(...), providing this method is convenient for method chaining.
  • new method Cffu.cffuJoin support timeout join ⏳ (323e14a)

🚗 Customizable CF

  • sticky default executor for *Async methods

🔮 backport CF functions from high java versions to Java 8

  • Cffu.java
    • timeout control methods orTimeout(...)/completeOnTimeout(...)
    • exceptionallyAsync()
    • exceptionallyCompose(...)/exceptionallyComposeAsync(...)
    • resultNow()/exceptionNow()
    • backport Future#state()
      • and add a new method cffuState() to works on Java 8
    • completeAsync(...)
    • minimalCompletionStage()
    • copy()
    • newIncompleteFuture()
  • CffuFactory.java
    • delay execution methods defaultExecutor(...)
    • completedStage(...)/failedStage(...)
    • failedFuture(...)

🍩 Kotlin support

  • extension methods of java implemented methods

🙌 Mics

  • make lib 0-dependence(optional Kotlin runtime is ok)
    implement tuple instead of common-lang3 dependency

☔️ Testing

👷 Chore

  • CI build/Github Action
    • support build by Java 19 and test by low version java(e.g. Java 8) (3a0c8e3)
      because the implementation used high java version api of CF
    • release maven SNAPSHOT to repo when main branch integration_test pass

CompletableFuture增强

目前CompletableFuture提供的都是最多两个入参的方法。

CompletableFuture<Map> future1 = CompletableFuture.supplyAsync(() -> {
    Map result = Maps.newHashMap();
    result.put("j", "j");
    return result;
});

future1.thenAccept((Map map) -> {
    System.out.println("thenAccept:" + map.get("j"));
});

future1.thenCombine(CompletableFuture.completedFuture("123"), (map, s) -> {
    System.out.println("thenCombine:" + map.get("j"));
    System.out.println(s);
    return "yy";
});

能否提供操作多个入参的工具类方法?
例如多个入参的消费accept/combine

Some API suggestions:)

Frist thanks for sharing, some suggestions below:

  1. Provides an extension definition for Kotlin ?
  2. Provides an extension for Vertx Function?
  3. How about keep the Cffu a clean room, and not extends the Future and CompletionStage directly, but provides methods like fromCompletionStage and toCompletionStage.
  4. then we can have method like failed instead of failedStage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.