Typical usage:
Async async = ctx.getService(asyncRef); ServiceReference<MyService> ref = ctx.getServiceReference(MyService.class); MyService mediator = async.mediate(ref, MyService.class); Promise<BigInteger> result = async.call(mediator.getSumOverAllValues());
The Promise API allows callbacks to be made when asynchronous tasks
complete, and can be used to chain Promises.
Multiple asynchronous tasks can be started concurrently, and will run in parallel if the Async Service has threads available.
| Modifier and Type | Method and Description |
|---|---|
| public <R> Promise | Returns: A Promise which can be used to retrieve the result of the asynchronous task.The return value of the mediated call, used for type
information. r)Invoke the last method call registered by a mediated object as an asynchronous task. |
| public Promise | Returns: A Promise which can be used to retrieve the result of the asynchronous task.Invoke the last method call registered by a mediated object as an asynchronous task. |
| public Promise | Returns: A Promise representing whether the fire-and-forget task was able to start.Invoke the last method call registered by a mediated object as a "fire-and-forget" asynchronous task. |
| public <T> T | |
| public <T> T | Returns: A mediator for the service object.The service reference to mediate. target, Class<T> The type that the mediated object should provide. iface)Create a mediator for the specified service. |
| call | back to summary |
|---|---|
| public <R> Promise Invoke the last method call registered by a mediated object as an asynchronous task. The result of the task can be obtained using the returned Promise. Typically the parameter for this method will be supplied inline like this: ServiceReference<I> s = ...; I i = async.mediate(s, I.class); Promise<String> p = async.call(i.foo());
| |
| call | back to summary |
|---|---|
| public Promise Invoke the last method call registered by a mediated object as an asynchronous task. The result of the task can be obtained using the returned Promise.
Generally it is preferable to use ServiceReference<I> s = ...; I i = async.mediate(s, I.class); Promise<String> p = async.call(i.foo()); However this pattern does not work for void methods. Void methods can therefore be handled like this: ServiceReference<I> s = ...; I i = async.mediate(s, I.class); i.voidMethod() Promise<?> p = async.call();
| |
| execute | back to summary |
|---|---|
| public Promise Invoke the last method call registered by a mediated object as a
"fire-and-forget" asynchronous task. This method should be used by
clients in preference to
The advantage of this method is that it allows for greater optimization
of the underlying asynchronous task. Clients are therefore likely to see
better performance when using this method compared to using
Typically this method is used like ServiceReference<I> s = ...; I i = async.mediate(s, I.class); i.someMethod() Promise<Void> p = async.execute(); | |
| mediate | back to summary |
|---|---|
| public <T> T mediate(T target, Class<T> iface) Create a mediator for the specified object. The mediator is a generated
object that registers the method calls made against it. The registered
method calls can then be run asynchronously using either the
The values returned by method calls made on a mediated object are opaque and should not be interpreted. Normal usage: I s = ...; I i = async.mediate(s, I.class); Promise<String> p = async.call(i.foo());
| |
| mediate | back to summary |
|---|---|
| public <T> T mediate(ServiceReference<? extends T> target, Class<T> iface) Create a mediator for the specified service. The mediator is a generated
object that registers the method calls made against it. The registered
method calls can then be run asynchronously using either the
The values returned by method calls made on a mediated object are opaque and should not be interpreted.
This method differs from Normal usage: ServiceReference<I> s = ...; I i = async.mediate(s, I.class); Promise<String> p = async.call(i.foo());
| |