Added notes to task handling test
This commit is contained in:
parent
e46a41dd8f
commit
4a7e4cb732
|
@ -11,6 +11,7 @@ async def main_cancel(i):
|
||||||
print(f"[main] Child spawned, waiting {i} seconds before canceling it")
|
print(f"[main] Child spawned, waiting {i} seconds before canceling it")
|
||||||
await structio.sleep(i)
|
await structio.sleep(i)
|
||||||
print("[main] Cancelling child")
|
print("[main] Cancelling child")
|
||||||
|
# Tasks can be cancelled individually, if necessary
|
||||||
task.cancel()
|
task.cancel()
|
||||||
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
|
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
|
||||||
|
|
||||||
|
@ -19,6 +20,13 @@ async def main_wait_successful():
|
||||||
print("[main] Parent is alive, spawning (and explicitly waiting for) child")
|
print("[main] Parent is alive, spawning (and explicitly waiting for) child")
|
||||||
t = structio.clock()
|
t = structio.clock()
|
||||||
async with structio.create_pool() as pool:
|
async with structio.create_pool() as pool:
|
||||||
|
# The spawn() method returns a Task object that can be
|
||||||
|
# independently managed if necessary. Awaiting the Task
|
||||||
|
# will wait for it to complete and return its return value,
|
||||||
|
# as well as propagate any exceptions it may raise. Note that
|
||||||
|
# in this example we could've just awaited the coroutine directly,
|
||||||
|
# so it's a bad show for the feature, but you could theoretically
|
||||||
|
# pass the object around somewhere else and do the awaiting there
|
||||||
print(f"[main] Child has returned: {await pool.spawn(successful, 'test', 5)}")
|
print(f"[main] Child has returned: {await pool.spawn(successful, 'test', 5)}")
|
||||||
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
|
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue