()
| 11 | return 2 |
| 12 | |
| 13 | async def main(): |
| 14 | await a() |
| 15 | await b() |
| 16 | print("serial\n") |
| 17 | |
| 18 | result = await asyncio.gather(a(), b()) |
| 19 | print("joined\n") |
| 20 | assert result == [1, 2] |
| 21 | |
| 22 | done, pending = await asyncio.wait( |
| 23 | [asyncio.create_task(a()), asyncio.create_task(b())], return_when=asyncio.FIRST_COMPLETED) |
| 24 | for p in pending: |
| 25 | p.cancel() |
| 26 | print("done {}\n".format(done.pop().result())) |
| 27 | |
| 28 | futures = [b(), a(), b()] |
| 29 | result = await asyncio.gather(*futures) |
| 30 | print("joined vector\n") |
| 31 | |
| 32 | if __name__ == "__main__": |
| 33 | # Python 3.7+ |
no test coverage detected