implementation "org.graceframework.plugins:async:6.3.0"
3 Usage
Version: 6.3.0
3 Usage
3.1 Async Plugin
To use the Async framework you should add a dependency on the async
plugin to your build.gradle
file:
By default the Promises
static methods use an instance of PromiseFactory
. This PromiseFactory
interface has various implementations.
The default implementation is CachedThreadPoolPromiseFactory which uses a thread pool that will create threads as needed (the same as java.util.concurrent.Executors.newCachedThreadPool()
)
However, the design of the promises framework is such that you can swap out the underlying implementation for your own or one of the pre-supported implementations.
For example to use RxJava 1.x simply add the RxJava dependency to build.gradle
:
implementation "org.graceframework:grace-async-rxjava:6.3.0"
The following table summarizes async framework support and the necessary dependency:
Framework | Dependency | Implementation Class |
---|---|---|
GPars 1.2.x |
|
|
RxJava 1.2.x |
|
|
RxJava 2.x |
|
|
RxJava 3.x |
|
|
3.2 Events Plugin
This project introduces a new Events API that replaces the previous implementation that was based on Reactor 2.x (which is no longer maintained and deprecated).
The Events framework introduces a new EventBus abstraction.
Like the PromiseFactory
notion, there are implementations of the EventBus
interface for common asynchronous frameworks like GPars and RxJava.
To use the Events abstraction you should add a dependency on the events
plugin to your build.gradle
file:
implementation "org.graceframework.plugins:events:6.3.0"
If no asynchronous framework in present on the classpath then by default Grace creates an EventBus based off of the currently active PromiseFactory
.
The default implementation is CachedThreadPoolPromiseFactory which uses a thread pool that will create threads as needed (the same as java.util.concurrent.Executors.newCachedThreadPool()
).
If you wish to use a popular async framework such as RxJava as the EventBus
implementation then you will need to add the appropriate dependency. For example for RxJava 1.x:
implementation "org.graceframework:grace-events-rxjava:6.3.0"
The following table summarizes async framework support and the necessary dependency:
Framework | Dependency | Implementation Class |
---|---|---|
GPars 1.2.x |
|
|
RxJava 1.2.x |
|
|
RxJava 2.x |
|
|
RxJava 3.x |
|
|