Package twisted :: Package flow :: Module wrap
[show private | hide private]
[frames | no frames]

Module twisted.flow.wrap

flow.wrap

This module provides the wrap() function in the flow module and the private classes used for its implementation.
Function Summary
  wrap(obj, *trap)
Wraps various objects for use within a flow

Variable Summary
SelectReactor reactor

Function Details

wrap(obj, *trap)

Wraps various objects for use within a flow

The following example illustrates many different
ways in which regular objects can be wrapped by
the flow module to behave in a cooperative manner.

    # required imports
    from __future__ import generators
    from twisted.flow import flow
    from twisted.internet import reactor, defer
    
    # save this function, it is used everwhere
    def printFlow(source):
        def printer(source):
            source = flow.wrap(source)
            while True:
                yield source
                print source.next()
        d = flow.Deferred(printer(source))
        d.addCallback(lambda _: reactor.stop())
        reactor.run()
  
    source = "string"
    printFlow(source)

    source = ["one",flow.Cooperate(1),"two"]
    printFlow(source)

    def source():
        yield "aeye"
        yield flow.Cooperate()
        yield "capin"
    printFlow(source)

    source = Deferred()
    reactor.callLater(1, lambda: source.callback("howdy"))
    printFlow(source)

Variable Details

reactor

Type:
SelectReactor
Value:
<twisted.internet.default.SelectReactor instance at 0x8220044>         

Generated by Epydoc 1.1 on Fri Jun 27 03:45:28 2003 http://epydoc.sf.net