Content deleted Content added
m Removed promotional language, added punctuation |
|||
Line 32:
===Deferreds===
Central to the Twisted application model is the concept of a ''deferred'' (elsewhere called a ''[[future (programming)|future]]''). A deferred is an instance of a class designed to receive and process a result which has not been computed yet, for example because it is based on data from a remote peer. Deferreds can be passed around, just like regular objects, but cannot be asked for their value. Each deferred supports a callback chain. When the deferred gets the value, it is passed to the functions on the callback chain, with the result of each callback becoming the input for the next. Deferreds make it possible to arrange to operate on the result of a function call before its value has become available.
For example, if a deferred returns a string from a remote peer containing an [[IP address]] in quad format, a callback can be attached to translate it into a 32-bit number. Any user of the deferred can now treat it as a deferred returning a 32-bit number. This, and the related ability to define "errbacks" (callbacks which are called as error handlers), allows code to specify in advance what to do when an asynchronous event occurs, without stopping to wait for the event. In non-event-driven systems, for example using [[thread (computing)|threads]], the operating system incurs premature and additional overhead organizing threads each time a blocking call is made. ===Thread support===
|