2019-11-13 11:08:22 +01:00
|
|
|
# Test that tasks return their value correctly to the caller
|
|
|
|
|
|
|
|
try:
|
2023-06-08 08:01:38 +02:00
|
|
|
import asyncio
|
2019-11-13 11:08:22 +01:00
|
|
|
except ImportError:
|
2023-06-08 08:01:38 +02:00
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
2019-11-13 11:08:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def foo():
|
|
|
|
return 42
|
|
|
|
|
|
|
|
|
|
|
|
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())
|