Encapsulates a callback and the calling of it. It handles these cases: * callback is None; do nothing * callback is async; create a task for it and run it on the event loop * callback is a regular function; call it synchronously on the next loop * caller has annotated with @to_thread; call it on threadpool Exceptions from the user callback are caught and logged. TODO: Also supports detection of args and kwargs as optional.??
| Method | __call__ |
How to actually call the callback. evt = EventCallback(...) evt() # or more explicitly, evt.call() |
| Method | __init__ |
@param obj The object initiating the callback (e.g. a certain stage or sprite). Usually this doesn't change for the lifetime of the callback setting. @param cb The callback. May be a regular or async function, or None for no action... |
| Method | clone |
Clone this handler to make a copy using the new object. Used during Sprite cloning to attach the same callbacks to the new object. Any existing tasks are not cloned. |
| Method | name |
@return the name given to this callback, mostly for debugging |
| Method | set |
Set/reset the callback to the given function 'cb'. If an existing previous callback is in progress, it is cancelled. @param cb A regular or async function. See class doc for details. May also be None. |
| Method | _call |
Call an 'async' callback as an asyncio task. Returns immediately after the task is scheduled. |
| Method | _call |
Do nothing when callback is None |
| Method | _call |
Call the callback synchronously while handling exceptions. Ensures we're on the UI thread as a safety measure. |
| Method | _call |
Kick the callback to a separate thread and treat that as the task. |
| Async Method | _safe |
Wrapper for calling the async callback and doing the housekeeping of the tracked task when finished. This ensures it runs in the same slice as the callback, as opposed to using add_done_callback(), which posts it additionally and could run later. |
| Method | _safe |
Call the callback synchronously while handling exceptions |
| Instance Variable | _cb |
Undocumented |
| Instance Variable | _do |
Undocumented |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _obj |
Undocumented |
| Instance Variable | _task |
Undocumented |
@param obj The object initiating the callback (e.g. a certain stage or sprite). Usually this doesn't change for the lifetime of the callback setting. @param cb The callback. May be a regular or async function, or None for no action. @param name Optional name used for debugging. If omitted, this will try to find the __name__ of the callback function.
Clone this handler to make a copy using the new object. Used during Sprite cloning to attach the same callbacks to the new object. Any existing tasks are not cloned.
Set/reset the callback to the given function 'cb'. If an existing previous callback is in progress, it is cancelled. @param cb A regular or async function. See class doc for details. May also be None.
Call the callback synchronously while handling exceptions. Ensures we're on the UI thread as a safety measure.