Part of twisted.internet.task View Source View In Hierarchy
A cooperative task is an iterator where each iteration represents an
atomic unit of work. When the iterator yields, it allows the
decide which of its tasks to execute next. If the iterator yields a
then work will pause until the
fires and completes its callback chain.
has more than one task, it distributes work between all tasks.
There are two ways to add tasks to a
is the more useful of the two, as it returns a
which can be
has the same effect, but returns only a
that fires when the task is done.
can be used for many things, including but not limited to:
Deferredto fire, doing the next thing, repeat (i.e. serializing a sequence of asynchronous tasks)
|Method||__init__||Create a scheduler-like object to which iterators may be added.|
|Method||coiterate||Add an iterator to the list of iterators this
|Method||cooperate||Start running the given iterator as a long-running cooperative task, by calling next() on it as a periodic timed event.|
|Method||start||Begin scheduling steps.|
|Method||stop||Stop scheduling steps. Errback the completion Deferreds of all iterators which have been added and forget about them.|
|Method||_tick||Run one scheduler tick.|
|Parameters||terminationPredicateFactory||A no-argument callable which will be invoked at the beginning of each step and should return a no-argument callable which will return True when the step should be terminated. The default factory is time-based and allows iterators to run for 1/100th of a second at a time.|
|scheduler||A one-argument callable which takes a no-argument callable and should invoke it at some future point. This will be used to schedule each step of this Cooperator.|
|started||A boolean which indicates whether iterators should be stepped as soon as
they are added, or if they will be queued up until |
Cooperatoris currently running.
|Parameters||doneDeferred||If specified, this will be the Deferred used as the completion deferred. It is suggested that you use the default, which creates a new Deferred for you.|
|Returns||a Deferred that will fire when the iterator finishes.|
|Parameters||iterator||the iterator to invoke.|