5.1 The Deferred Event API

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.


\begin{listing}
% latex2html id marker 1099\begin{small}\begin{verbatim}pack...
...nd{verbatim} \end{small}\caption{Reactor Deferred Factory Methods}
\end{listing}

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.


\begin{listing}
% latex2html id marker 1113\begin{small}\begin{verbatim}pack...
...verbatim} \end{small}\caption{Deferred Event Interface Definition}
\end{listing}


\begin{listing}
% latex2html id marker 1121\begin{small}
\begin{verbatim}pac...
...verbatim}
\end{small}\caption{The Deferrable Interface Definition}
\end{listing}

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.