Overview:
-
The gather() function starts and runs multiple awaitables concurrently, grouping them as a Future.
-
Awaiting on the returned Future object runs the awaitables to completion and returns the results.
Example:
# An example Python program that # A coroutine that generates odd numbers # A coroutine that generates even numbers # Coroutine that is bootstrapped by el = asyncio.new_event_loop() |
Output:
From oddgen:1 From oddgen:3 From evengen:0 From evengen:2 From oddgen:5 From evengen:4 From evengen:6 From evengen:8 From evengen:10 Results from asyncio.gather():[5, 10] |