2019-11-13 05:08:22 -05:00
|
|
|
# Test that tasks return their value correctly to the caller
|
|
|
|
|
|
|
|
try:
|
2023-08-22 11:15:46 -04:00
|
|
|
import asyncio
|
2019-11-13 05:08:22 -05:00
|
|
|
except ImportError:
|
2023-08-22 11:15:46 -04:00
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
2019-11-13 05:08:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
async def foo():
|
|
|
|
return 42
|
|
|
|
|
|
|
|
|
2023-08-20 09:02:31 -04:00
|
|
|
try:
|
|
|
|
foo().__await__
|
|
|
|
except AttributeError:
|
|
|
|
print("SKIP")
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
2019-11-13 05:08:22 -05:00
|
|
|
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())
|