6.6 Threadable Task Timeouts

The type of behaviour demonstrated by the example given in Listing 6.9 can be useful for managing threadable tasks which may block during execution. This essentially provides a timeout on the threadable execution - cancelling it if an underlying call blocks for an unexpectedly long time.

Support for implementing this type of timeout behaviour is included in the API via an alternate form of the runThreadable method which includes an extra timeout parameter. This method variant will execute the threadable task as previously described, but it also sets a timeout on the deferred callback which will automatically cancel the thread when the execution time exceeds the specified timeout period.

The initial timeout period must be specified when making the initial call to the runThreadable method. However, the timeout behaviour may subsequently be modified by calling the setTimeout and cancelTimeout methods on the returned deferred event object, as previously described in Section 5.10.