QUERY · ISSUE
docs: add custom coroutinemethod/coroutinefunction directives following CPython
docs
For documenting async functions/methods, CPython now uses, eg:
.. coroutinemethod:: read(n=-1)
Read up to *n* bytes. If *n* is not provided, or set to ``-1``,
read until EOF and return all read bytes.
If EOF was received and the internal buffer is empty,
return an empty ``bytes`` object.
I think it'd be good to do this in MicroPython's docs.
CANDIDATE · PULL REQUEST
extmod/asyncio: Add `Task` methods from CPython
extmod
This updates the way that Task is defined in the C module for asyncio which implements tasks & task queues. The goal is to bring asyncio in MicroPython slightly closer to CPython.
This adds the following methods to Task:
get_coro()- how CPython exposes the coroutine backing the task (CPython Docs)result()- a helper method from CPython for returning the successful response (CPython Docs)exception()- a helper method from CPython for returning the raised values (CPython Docs)cancelled()- helper for true / false if the task has been cancelled (CPython Docs)add_done_callback()- adds a callback to the task for completion or if already complete executes it (CPython docs)remove_done_callback()- removes a specific "done" callback from the task (CPython docs)
~Adds a hash unary operation so Tasks can be added to sets like in CPython.~
~Also adds set_result and set_exception for consistency but neither of these do anything - they raise a RuntimeError because they aren't supported on Tasks. :shrug:~