Skip to content

Reakt Reactive Java, Streaming, Promises Lib 2.6.0.RELEASE

Choose a tag to compare

@RichardHightower RichardHightower released this 28 Apr 02:09

Please read docs. We added many more docs.
Also see updated Reakt Reactive Java website.

  • Added thenPromise to chain a promise to another
  • Added invokeWithPromise for unit testing invokable promises
  • Improved exception handling
  • Added Safe handlers thenSafe and thenSafeExpect to help debug async libs that eat exceptions

We added some methods to Promise to make testing and using invokable promises easier.

thenPromise, invokeWithPromise

...
interface Promise {
    ...
    /**
     * Allows you to pass an existing promise as a handler.
     * @param promise promise
     * @return this, fluent
     */
    default Promise<T> thenPromise(Promise<T> promise) {
        this.catchError(promise::reject).then(promise::resolve);
        return this;
    }

    /**
     * Allows you to pass an existing promise as a handler.
     * @param promise promise
     * @return this, fluent
     */
    default Promise<T> invokeWithPromise(Promise<T> promise) {
        thenPromise(promise).invoke();
        return this;
    }

The above methods are very convienient for unit testing invokable promises.

Example using invokeWithPromise for unit testing an Invokable promise

    @Test
    public void testAsyncServiceWithInvokeWithPromise() {

        Promise<URI> promise = Promises.blockingPromise();
        promise.then(this::handleSuccess)
                .catchError(this::handleError);

        asyncServiceDiscovery.lookupService(empURI).invokeWithPromise(promise);

        final Expected<URI> expect = promise.expect();

        assertFalse(expect.isEmpty());

        assertNotNull("We have a return from async", returnValue.get());
        assertNull("There were no errors form async", errorRef.get());
        assertEquals("The result is the expected result form async", successResult, returnValue.get());
    }

Exceptions

Reakt throws exceptions when you call get() on a result or promise and the result or promise
is in an error state.

If the cause is a RuntimeException, then the original exception will be thrown.
If the cause is not a RuntimeException, then it will be wrapped in on of the following RuntimeExceptions.

  • RejectedPromiseException - The promise was rejected with a non-runtime Exception.
  • ResultFailedException - The result failed due to a non-runtime Exception.
  • ThenHandlerException - The promise was successful but your then handler or thenExpect handler threw an exception.

We added safe handlers, namely, thenSafe and thenSafeExpect, so your exceptions don't get lost in an async thread.