Skip to content

extmod/uasyncio: Provide asyncio.iscoroutine function. #11526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/library/uasyncio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Core functions

This is a coroutine, and a MicroPython extension.

.. function:: iscoroutine(obj)

Return True if obj is a coroutine object.

Additional functions
--------------------

Expand Down
7 changes: 6 additions & 1 deletion extmod/uasyncio/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ def _promote_to_task(aw):
return aw if isinstance(aw, Task) else create_task(aw)


# Return True if obj is a coroutine object
def iscoroutine(obj):
return hasattr(obj, "send")


# Create and schedule a new task from a coroutine
def create_task(coro):
if not hasattr(coro, "send"):
if not iscoroutine(coro):
raise TypeError("coroutine expected")
t = Task(coro, globals())
_task_queue.push(t)
Expand Down