extmod/uasyncio: Add asyncio.current_task().
Matches CPython behavior. Fixes #6686
This commit is contained in:
parent
d128999938
commit
7ed99544e4
|
@ -40,6 +40,10 @@ Core functions
|
|||
|
||||
Returns the corresponding `Task` object.
|
||||
|
||||
.. function:: current_task()
|
||||
|
||||
Return the `Task` object associated with the currently running task.
|
||||
|
||||
.. function:: run(coro)
|
||||
|
||||
Create a new task from the given coroutine and run it until it completes.
|
||||
|
|
|
@ -264,6 +264,10 @@ def get_event_loop(runq_len=0, waitq_len=0):
|
|||
return Loop
|
||||
|
||||
|
||||
def current_task():
|
||||
return cur_task
|
||||
|
||||
|
||||
def new_event_loop():
|
||||
global _task_queue, _io_queue
|
||||
# TaskQueue of Task instances
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# Test current_task() function
|
||||
|
||||
try:
|
||||
import uasyncio as asyncio
|
||||
except ImportError:
|
||||
try:
|
||||
import asyncio
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
async def task(result):
|
||||
result[0] = asyncio.current_task()
|
||||
|
||||
|
||||
async def main():
|
||||
result = [None]
|
||||
t = asyncio.create_task(task(result))
|
||||
await asyncio.sleep(0)
|
||||
await asyncio.sleep(0)
|
||||
print(t is result[0])
|
||||
|
||||
|
||||
asyncio.run(main())
|
|
@ -0,0 +1 @@
|
|||
True
|
Loading…
Reference in New Issue