Reakt Reactive Java, Streaming, Promises Lib 2.5.0.RELEASE
RichardHightower
released this
21 Apr 05:42
·
41 commits
to master
since this release
- Reakt Promises and Callbacks are now also Consumers. Issue 18
- Reakt now supports invokable promises Issue 17, Invokable Promise Docs
- Added utility methods for sending back null and for working with Promise, Callback, (
reply
with no args andreplyDone
) 16, 17
Invokable promise was the biggest thing we added in this release so please read Invokable Promise Docs.
Reakt Promises and Callbacks are now also Consumers. This allows you to use Reakt Promises with projects and libs that have no concept of Reakt.
A Callback is now a Consumer that has an errorConsumer
//Now extends Consumer
public interface Callback<T> extends Consumer<T> {
...
default void accept(T t) { reply(t);}
default Consumer<Throwable> errorConsumer() { return this::reject; }
default Consumer<T> consumer() { return this; }
...
//A promise is a callback and a result as before
public interface Promise<T> extends Callback<T>, Result<T> {
If you had the following service.
Example integration
...
public class EmployeeService {
public void lookupEmployee(String id, Consumer<Employee> employeeConsumer,
Consumer<Throwable> errorConsumer) {
//lookup employee async.
employeeConsumer.accept(employee); // or call errorConsumer(exception);
...
}
Example integration
You could call it like this.
Promise promise = Promises.promise();
promise.catchError((error)->...).then((employee)->...);
employeeService.lookupEmployee("123", promise.consumer(), promise.errorConsumer());