Interface Deferred<D>
- Type Parameters:
D- Type used for resolved value
- All Known Implementing Classes:
DeferredObject
Deferred interface to trigger an event (resolve, reject, notify).
Subsequently, this will allow Promise observers to listen in on the event
(done, fail, progress).
- Author:
- Ray Tsang
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface cn.dinodev.spring.commons.promise.Promise
Promise.State -
Method Summary
Methods inherited from interface cn.dinodev.spring.commons.promise.Promise
always, done, fail, getOrElse, getOrElse, isPending, isRejected, isResolved, state, then, then, waitSafely, waitSafely
-
Method Details
-
resolve
This should be called when a task has completed successfully.Deferred deferredObject = new DeferredObject(); Promise promise = deferredObject.promise(); promise.done(result -> { // Done! }); // another thread using the same deferredObject deferredObject.resolve("OK");- Parameters:
resolve- the resolved value for thisDeferred- Returns:
- the reference to this
Deferredinstance.
-
reject
This should be called when a task has completed unsuccessfully, i.e., a failure may have occurred.Deferred deferredObject = new DeferredObject(); Promise promise = deferredObject.promise(); promise.fail(error -> { // Failed :( }); // another thread using the same deferredObject deferredObject.reject("BAD");- Type Parameters:
F- Type of the exception/error- Parameters:
reject- the rejected value for thisDeferred- Returns:
- the reference to this
Deferredinstance.
-
promise
Return anPromiseinstance (i.e., an observer). You can register callbacks in this observer.- Returns:
- the reference to this
Deferredinstance as aPromise,
-