Module: cogen.core.events

Base events (coroutine operations) and coroutine exceptions.

Classes

AddCoro

A operator for adding a coroutine in the scheduler. Example:

yield events.AddCoro(some_coro, args=(), kwargs={})

Call

This will pause the current coroutine, add a new coro in the scheduler and resume the callee when it returns.

Usage:
result = yield events.Call(mycoro, args=<a tuple>, kwargs=<a dict>, prio=<int>)
  • if prio is set the new coroutine will be added in the top of the
scheduler queue

ConnectionClosed

Raised when the other peer has closed connection.

Join

A operator for waiting on a coroutine. Example:

@coroutine
def coro_a():
    return_value = yield events.Join(ref)
    
    
@coroutine
def coro_b():
    yield "bla"
    raise StopIteration("some return value")

ref = scheduler.add(coro_b)
scheduler.add(coro_a)

OperationTimeout

Raised when the timeout for a operation expires. The exception message will be the operation

Signal

This will resume the coroutines that where paused with WaitForSignal.

Usage:

nr = yield events.Signal(name, value)
  • nr - the number of coroutines woken up

Sleep

Usage:

yield events.Sleep(time_object)
  • timeoject - a datetime or timedelta object, or a number of seconds
yield events.Sleep(timestamp=ts)
  • ts - a timestamp

WaitForSignal

The coroutine will resume when the same object is Signaled.