# Class k.t.Tasklet(object):

Part of kiwi.tasklet View In Hierarchy

An object that launches and manages a tasklet.

Instance Variables | state | current execution state of the tasklet, one of the STATE_* contants.
| return_value | the value returned by the task function, or None.
Class Variables | STATE_RUNNING | the tasklet function is currently executing code
| STATE_SUSPENDED | the tasklet function is currently waiting for an event
| STATE_MSGSEND | the tasklet function is currently sending a message
| STATE_ZOMBIE | the tasklet function has ended

Method | __init__ | Launch a generator tasklet.
Method | start | Starts the execution of the task, for use with tasklets
Method | get_message_actions | Dictionary mapping message names to actions ('accept' or
Method | run | Method that executes the task.
Method | _invoke | Undocumented
Method | _next_round | Undocumented
Method | _dispatch_message | get next message that a tasklet wants to receive; discard
Method | _update_wait_conditions | disarm wait conditions removed and arm new wait conditions
Method | wait_condition_fired | Method that should be called when a wait condition fires
Method | add_join_callback | Add a callable to be invoked when the tasklet finishes.
Method | remove_join_callback | Remove a join callback previously added with `add_join_callback`
Method | _join | Undocumented
Method | send_message | Send a message to be received by the tasklet as an event.

def __init__(self, gen=None, start=True):
Launch a generator tasklet.

Parameters | gen | a generator object that implements the tasklet main body
| start | whether to automatically start running the tasklet in the constructor If `gen` is omitted or None, `run` should be overridden in a subclass.

def start(self):
Starts the execution of the task, for use with tasklets created with start=False

def get_message_actions(self):
Dictionary mapping message names to actions ('accept' or 'discard' or 'defer'). Should normally not be accessed directly by the programmer.

def run(self):

Method that executes the task.

Should be overridden in a subclass if no generator is passed into the constructor.

Note | do NOT call this method directly; it is meant to be called by the tasklet framework.

def _invoke(self):
Undocumented
def _next_round(self):
Undocumented
def _dispatch_message(self):
get next message that a tasklet wants to receive; discard messages that should be discarded

def _update_wait_conditions(self, old_wait_list):
disarm wait conditions removed and arm new wait conditions

def wait_condition_fired(self, triggered_cond):
Method that should be called when a wait condition fires

def add_join_callback(self, callback, *extra_args):

Add a callable to be invoked when the tasklet finishes. Return a connection handle that can be used in remove_join_callback()

The callback will be called like this:

         callback(tasklet, retval, *extra_args)

where tasklet is the tasklet that finished, and retval its return value (or None).

When a join callback is invoked, it is automatically removed, so calling `remove_join_callback` afterwards produces a KeyError exception.

def remove_join_callback(self, handle):
Remove a join callback previously added with `add_join_callback`

def _join(self, retval):
Undocumented
def send_message(self, message):
Send a message to be received by the tasklet as an event.

Note | Don't call this from another tasklet, only from the main loop! To send a message from another tasklet, yield a `Message` with a correctly set 'dest' parameter.