items with addressing information and dispatches them to an appropriate
output, stripping the addressing information off.
Use like so:
from tubes.tube import receiver, series from tubes.routing import Router, to aRouter = Router() evens = aRouter.newRoute() odds = aRouter.newRoute() @receiver() def evenOdd(item): if (item % 2) == 0: yield to(evens, item) else: yield to(odds, item) numbers.flowTo(series(evenOdd, aRouter.drain))
numbers is a fount of counting integers, this
creates two founts:
odds, whose outputs
are even and odd integers, respectively. Note that
odds as addresses; the
first argument to
where the value will go.
Why do this rather than just having
evenOdd just call
methods directly based on whether a number is even or odd?
By using a
flow control relationships are automatically preserved by the same
mechanism that tubes usually use. The distinct drains of
odds can both independently pause their
founts, and the pause state will be propagated to the "numbers"
fount. If you want to send on outputs to multiple drains which may have
complex flow-control interrelationships, you can't do that by calling the
receive method directly since any one of those methods might
reentrantly pause its fount.
|Function||to||Construct a provider of
|Class||Router||A drain with multiple founts that consumes
|Class||_To||An object destined for a specific destination.|
Construct a provider of
|Parameters||where||A fount returned from |
|what||the value to deliver.|