Union of multiple event sources
Example usage:
timedOut = scheduler.timeout(30)
untilSomethingHappens = events.AnyOf(stream.dataRcvd, timedOut)
while not timedOut():
yield untilSomethingHappens; src,evt = events.resume()
if src is stream.dataRcvd:
data = event
print data
AnyOf fires callbacks whenever any of its actual event sources fire (and
allows tasks to continue if any of its actual event sources allow it).
The event it supplies to its user is actually a (source,event) tuple
as shown above, so you can distinguish which of the actual event sources
fired, as well as receive the event from it.
Note that callbacks registered with an AnyOf instance will fire at most
once, even if more than one of the original event sources fires. Thus,
you should not assume in a callback or task that the event you received
is the only one that has occurred. This is especially true in scheduled
tasks, where many things may happen between the triggering of an event
and the resumption of a task that was waiting for the event.
Methods
|
|
__new__
addCallback
nextAction
|
|
__new__
|
__new__ ( klass, *sources )
Exceptions
|
|
ValueError, "AnyOf must be called with one or more IEventSources"
|
|
|
addCallback
|
addCallback ( self, func )
See events.IEventSource.addCallback()
|
|
nextAction
|
nextAction (
self,
task=None,
state=None,
)
See events.ITaskSwitch.nextAction()
|
|