summaryrefslogtreecommitdiffstatshomepage
path: root/tests/ports/webassembly/asyncio_top_level_await.mjs
blob: d8a9cad422e9b4b97e61fa6db788c10ba8f6cfd8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Test top-level await on asyncio primitives: Task, Event.

const mp = await (await import(process.argv[2])).loadMicroPython();

await mp.runPythonAsync(`
import asyncio

async def task(event):
    print("task set event")
    event.set()
    print("task sleep")
    await asyncio.sleep(0.1)
    print("task end")

event = asyncio.Event()
t = asyncio.create_task(task(event))

print("top-level wait event")
await event.wait()
print("top-level wait task")
await t
print("top-level end")
`);

console.log("finished");