Deferred events are managed within the Reaction framework using deferred event objects. The reactor core acts as a factory for these objects and the standard reactor interface (Reactor) provides the API shown in Listing 5.1.
The newDeferred factory method will return an object which implements the Deferred interface as shown in Listing 5.2. Such objects are referred to here as being deferred event objects since they encapsulate all the state associated with a single deferred callback event. The Deferred interface provides methods for attaching deferrable objects (ie, those implementing Deferrable) and for triggering callbacks on the deferred event.
Of the methods provided by the deferred event interface, the callback and errback methods are used for triggering event callbacks and the addDeferrable method is used to attach deferrable objects to the deferred event object in order to receive those callbacks. The setTimeout and cancelTimeout methods are used for managing callback timeouts and the discard method provides a clean way of `ignoring' deferred callbacks. All these API methods will be discussed in more detail in the following sections.