circuitpython/tests/extmod/asyncio_await_return.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
471 B
Python
Raw Normal View History

# Test that tasks return their value correctly to the caller
try:
2023-08-22 11:15:46 -04:00
import asyncio
except ImportError:
2023-08-22 11:15:46 -04:00
print("SKIP")
raise SystemExit
async def foo():
return 42
try:
foo().__await__
except AttributeError:
print("SKIP")
raise SystemExit
async def main():
# Call function directly via an await
print(await foo())
# Create a task and await on it
task = asyncio.create_task(foo())
print(await task)
asyncio.run(main())