Package twisted :: Package internet :: Module defer :: Class Deferred |
[show private | hide private]
[frames | no frames]

## Class Deferred

Known Subclasses:
  `DeferredList`, `_Defer`

This is a callback which will be put off until later.

Why do we want this? Well, in cases where a function in a threaded program would block until it gets a result, for Twisted it should not block. Instead, it should return a Deferred.

This can be implemented for protocols that run over the network by writing an asynchronous protocol for twisted.internet. For methods that come from outside packages that are not under our control, we use threads (see for example `twisted.enterprise.adbapi`).

For more information about Deferreds, see doc/howto/defer.html or http://www.twistedmatrix.com/documents/howto/defer

Method Summary
| `__init__(self)`
| ``__del__`(self)` Print tracebacks and die.
| `__repr__(self)`
| `__str__(self)`
| ``addBoth`(self, callback, *args, **kw)` Convenience method for adding a single callable as both a callback and an errback.
| ``addCallback`(self, callback, *args, **kw)` Convenience method for adding just a callback.
| ``addCallbacks`(self, callback, errback, callbackArgs, callbackKeywords, errbackArgs, errbackKeywords, asDefaults)` Add a pair of callbacks (success and error) to this Deferred.
| ``addErrback`(self, errback, *args, **kw)` Convenience method for adding just an errback.
| ``arm`(self)` This method is deprecated.
| ``armAndCallback`(self, result)` Run all success callbacks that have been added to this Deferred.
| ``armAndChain`(self, d)` Chain another Deferred to this Deferred.
| ``armAndErrback`(self, fail)` Run all error callbacks that have been added to this Deferred.
| ``callback`(self, result)` Run all success callbacks that have been added to this Deferred.
| ``chainDeferred`(self, d)` Chain another Deferred to this Deferred.
| ``errback`(self, fail)` Run all error callbacks that have been added to this Deferred.
| ``pause`(self)` Stop processing on a Deferred until `unpause`() is called.
| ``setTimeout`(self, seconds, timeoutFunc, *args, **kw)` Set a timeout function to be triggered if I am not called.
| ``unpause`(self)` Process all callbacks made since `pause`() was called.
| `_continue(self, result, isError)`
| `_runCallbacks(self)`
| `_startRunCallbacks(self, result, isError)`

Class Variable Summary
`int` | `called`
`int` | `default`
`int` | `paused`
`NoneType` | `timeoutCall`

Method Details

### __del__(self) (Destructor) Print tracebacks and die. If the *last* (and I do mean *last*) callback leaves me in an error state, print a traceback (if said errback is a Failure).

### addBoth(self, callback, *args, **kw) Convenience method for adding a single callable as both a callback and an errback. See `addCallbacks`.

### addCallback(self, callback, *args, **kw) Convenience method for adding just a callback. See `addCallbacks`.

### addCallbacks(self, callback, errback=None, callbackArgs=None, callbackKeywords=None, errbackArgs=None, errbackKeywords=None, asDefaults=0) Add a pair of callbacks (success and error) to this Deferred. These will be executed when the 'master' callback is run.

### addErrback(self, errback, *args, **kw) Convenience method for adding just an errback. See `addCallbacks`.

### arm(self) This method is deprecated.

### armAndCallback(self, result) Run all success callbacks that have been added to this Deferred. Each callback will have its result passed as the first argument to the next; this way, the callbacks act as a 'processing chain'. Also, if the success-callback returns a Failure or raises an Exception, processing will continue on the *error*- callback chain.

### armAndChain(self, d) Chain another Deferred to this Deferred. This method adds callbacks to this Deferred to call d's callback or errback, as appropriate.

### armAndErrback(self, fail=None) Run all error callbacks that have been added to this Deferred. Each callback will have its result passed as the first argument to the next; this way, the callbacks act as a 'processing chain'. Also, if the error-callback returns a non-Failure or doesn't raise an Exception, processing will continue on the *success*-callback chain. If the argument that's passed to me is not a failure.Failure instance, it will be embedded in one. If no argument is passed, a failure.Failure instance will be created based on the current traceback stack. Passing a string as `fail' is deprecated, and will be punished with a warning message.

### callback(self, result) Run all success callbacks that have been added to this Deferred. Each callback will have its result passed as the first argument to the next; this way, the callbacks act as a 'processing chain'. Also, if the success-callback returns a Failure or raises an Exception, processing will continue on the *error*- callback chain.

### chainDeferred(self, d) Chain another Deferred to this Deferred. This method adds callbacks to this Deferred to call d's callback or errback, as appropriate.

### errback(self, fail=None) Run all error callbacks that have been added to this Deferred. Each callback will have its result passed as the first argument to the next; this way, the callbacks act as a 'processing chain'. Also, if the error-callback returns a non-Failure or doesn't raise an Exception, processing will continue on the *success*-callback chain. If the argument that's passed to me is not a failure.Failure instance, it will be embedded in one. If no argument is passed, a failure.Failure instance will be created based on the current traceback stack. Passing a string as `fail' is deprecated, and will be punished with a warning message.

### pause(self) Stop processing on a Deferred until `unpause`() is called.

### setTimeout(self, seconds, timeoutFunc=<function timeout at 0x82b16fc>, *args, **kw) Set a timeout function to be triggered if I am not called. Parameters: `seconds` - How long to wait (from now) before firing the timeoutFunc. `timeoutFunc` - will receive the Deferred and *args, **kw as its arguments. The default timeoutFunc will call the errback with a `TimeoutError`.

### unpause(self) Process all callbacks made since `pause`() was called.

Class Variable Details

    ### called Type: `int` Value:
        0

    ### default Type: `int` Value:
        0

    ### paused Type: `int` Value:
        0

    ### timeoutCall Type: `NoneType` Value:
        None

Generated by Epydoc 1.1 on Thu May 8 13:18:26 2003 | http://epydoc.sf.net