Iteration, Twisted style!

This module contains multitudes; consider it carefully. It provides a way of dealing with iterations asynchronously. The Deferator yields Deferred objects, an asynchronous version of an iterator.

Even cooler is IterationProducer, which produces iterations to an implementor of twisted.internet.interfaces.IConsumer. You can make one out of an iterator with iteratorToProducer.

The Delay object is also very useful, both as a Deferred-after-delay callable and a way to get a Deferred that fires when an event occurs. This is the key to getting process.ProcessWorker to work so nicely via Python's standard multiprocessing module.

Function deferToDelay Returns a Deferred that fires after the specified delay (in seconds).
Function isIterator
Class Delay I let you delay things and wait for things that may take a while, in Twisted fashion.
Class Deferator Deferred-yielding iterator.
Class Prefetcherator I prefetch iterations from an iterator, providing a getNext method suitable for Deferator.
Class ListConsumer Bare-bones iteration consumer.
Class IterationProducer Producer of iterations from a Deferator.
Function iteratorToProducer Makes an iterator into an IterationProducer.
def deferToDelay(delay):

Returns a Deferred that fires after the specified delay (in seconds).

def isIterator(x):
@defer.inlineCallbacks
def iteratorToProducer(iterator, consumer=None, wrapper=None):

Makes an iterator into an IterationProducer.

Converts a possibly slow-running iterator into a Twisted-friendly producer, returning a deferred that fires with the producer when it's ready. If the the supplied object is not a suitable iterator (perhaps empty), the result will be None.

If a consumer is not supplied, whatever consumer gets this must register with the producer by calling its non-interface method IterationProducer.registerConsumer and then its IterationProducer.run method to start the iteration/production.

If you supply a consumer, those two steps will be done automatically, and this method will fire with a Deferred that fires when the iteration/production is done.

API Documentation for AsynQueue, generated by pydoctor at 2022-11-17 13:13:24.