1try:
2    import uasyncio as asyncio
3except ImportError:
4    try:
5        import asyncio
6    except ImportError:
7        print("SKIP")
8        raise SystemExit
9
10
11try:
12    import utime
13
14    ticks = utime.ticks_ms
15    ticks_diff = utime.ticks_diff
16except:
17    import time
18
19    ticks = lambda: int(time.time() * 1000)
20    ticks_diff = lambda t1, t0: t1 - t0
21
22
23async def delay_print(t, s):
24    await asyncio.sleep(t)
25    print(s)
26
27
28async def main():
29    print("start")
30
31    await asyncio.sleep(0.001)
32    print("after sleep")
33
34    t0 = ticks()
35    await delay_print(0.02, "short")
36    t1 = ticks()
37    await delay_print(0.04, "long")
38    t2 = ticks()
39    await delay_print(-1, "negative")
40    t3 = ticks()
41
42    print(
43        "took {} {} {}".format(
44            round(ticks_diff(t1, t0), -1),
45            round(ticks_diff(t2, t1), -1),
46            round(ticks_diff(t3, t2), -1),
47        )
48    )
49
50
51asyncio.run(main())
52