Releases: advantageous/reakt
Reakt 4.0.1
Simplified Promise and Callback interfaces.
Created PromiseHandler and CallbackHandler to hide the complexity.
Reakt Reactive Java, Streaming, Promises Lib 3.0.4.RELEASE
- Added methods to make API more fluent (for invokeable promises).
- Bug fixes for Reactor timeout handling.
- Bug fixes for ReplayPromise
replay
. - Changes to
BasePromise
to ensure handlers are never called twice. Promise.all
,Reactor.all
fixes.- Blocking promise support for testing and legacy integration.
If you are using an older version of Reakt, then you should upgrade.
Reakt Reactive Java, Streaming, Promises Lib 2.8.1.RELEASE
Reakt Reactive Java, Streaming, Promises Lib 2.6.0.RELEASE
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
andthenSafeExpect
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 yourthen
handler orthenExpect
handler threw an exception.
We added safe handlers, namely, thenSafe
and thenSafeExpect
, so your exceptions don't get lost in an async thread.
Reakt Reactive Java, Streaming, Promises Lib 2.5.0.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());
Reakt Reactive Java, Streaming, Promises Lib 2.4.0.RELEASE
We closed the following issues.
- 16 utility methods for Promise (replyDone and resolve)
- 15 empty resolve method for and returning null (matches ES6)
- 14 Utility methods for Java basic types.
We need this in both the reactor Promises.
class Promises
/**
* Returns a String promise
* Added to make static imports possible.
*
* @return returns a string promise
*/
static Promise<String> promiseString() {
return new BasePromise<>();
}
/**
* Returns a Integer promise
* Added to make static imports possible.
*
* @return returns an int promise
*/
static Promise<Integer> promiseInt() {
return new BasePromise<>();
}
/**
* Returns a Long promise
* Added to make static imports possible.
*
* @return returns an long promise
*/
static Promise<Long> promiseLong() {
return new BasePromise<>();
}
/**
* Returns a Double promise
* Added to make static imports possible.
*
* @return returns an double promise
*/
static Promise<Double> promiseDouble() {
return new BasePromise<>();
}
/**
* Returns a Float promise
* Added to make static imports possible.
*
* @return returns an float promise
*/
static Promise<Float> promiseFloat() {
return new BasePromise<>();
}
/**
* Returns a void promise for notify of outcome but no value returned.
* <p>
* Callback replyDone can be used instead of replay on service side.
*
* @return void promise
*/
static Promise<Void> promiseNotify() {
return new BasePromise<>();
}
/**
* Boolean promise
* Added to make static imports possible.
*
* @return promises a boolean
*/
static Promise<Boolean> promiseBoolean() {
return new BasePromise<>();
}
/**
* Generic promise.
* Added to make static imports possible.
*
* @param cls type
* @param <T> promise of a result of T
* @return new Promise of type T
*/
@SuppressWarnings("unused")
static <T> Promise<T> promise(Class<T> cls) {
return new BasePromise<>();
}
/**
* Generic list promise.
* Added to make static imports possible.
*
* @param componentType component type of list
* @param <T> promise a list of type T
* @return new Promise for a list of type T
*/
@SuppressWarnings("unused")
static <T> Promise<List<T>> promiseList(Class<T> componentType) {
return new BasePromise<>();
}
/**
* Generic collection promise.
* Added to make static imports possible.
*
* @param componentType component type of collection
* @param <T> promise a collection of type T
* @return new Promise for a collection of type T
*/
@SuppressWarnings("unused")
static <T> Promise<Collection<T>> promiseCollection(Class<T> componentType) {
return new BasePromise<>();
}
/**
* Generic map promise.
* Added to make static imports possible.
*
* @param keyType type of map key
* @param valueType type of map value
* @param <K> promise a map of key type K
* @param <V> promise a map of value type V
* @return new Promise for a collection of type T
*/
@SuppressWarnings("unused")
static <K, V> Promise<Map<K, V>> promiseMap(Class<K> keyType, Class<V> valueType) {
return new BasePromise<>();
}
/**
* Generic set promise.
* Added to make static imports possible.
*
* @param componentType component type of set
* @param <T> promise a set of type T
* @return new Promise for a set of type T
*/
@SuppressWarnings("unused")
static <T> Promise<Set<T>> promiseSet(Class<T> componentType) {
return new BasePromise<>();
}
We also have them for the reactor (methods off of the reactor), and we have them for blocking and replay promises off of Promises utility class. This makes the fluent programming a bit nicer. Especially if you are using static imports of Promises
.
Reakt 2.3.0.RELEASE
- Fixed bug with thenMap with blocking promise
- Added utility methods to promises API (to allow static import, and fluent usage)
Reakt 2.1.0.RELEASE
Change group to io.advantageous.reakt.
Reakt 2.0.0.RELEASE
We went to version 2.x because we are using semantic versioning and we changed the interface in a breaking way.
Ref
has been renamed to Expected
.
Result.getRef()
has been renamed to Result.expect()
.
Result.thenRef()
has been renamed to Result.thenExpect()
.
We added a orElse
to Result
and this allows you to provide a default value if the result resulted in an error.
Note that a Promise
is a Result
and a promise is a Callback
, thus, it has the same changes as Result
.
Reakt 1.0.0.RELEASE
- Added
Reactor
which enablesReplayPromises
, and is heavily based on the QBitReactor
. - Added
Promises.all
andPromises.any
support. - Changed methods
reply
andfail
toresolve
andreject
in Callback and Promise to match the JS Promises API so someone form JS or ES6 could more readily reason on them. We kept the namereply
as an alias forresolve
because it fits service callbacks better. - Added support for
thenMap
and whenwhenComplete
. thenMap examples - We also added
Breaker
which is like aRef
but used for managing services that might go down. Breaker is short forCircuitBreaker
. - Wrote more documentation.