Skip to content

Add additional concurrency primitives #88

@chriso

Description

@chriso

The SDK provides a gather function that concurrently runs zero or more awaitables, and blocks until all awaitables return successfully or any awaitable raises.

async def gather(*awaitables: Awaitable[Any]) -> list[Any]: ...

The name was chosen to match the asyncio function that has the same behavior. See https://docs.python.org/3/library/asyncio-task.html#running-tasks-concurrently.

Other languages provide a more complete set of concurrency/composition primitives. For example, JavaScript provides Promise.all, Promise.any and Promise.race:

  • all: returns when all awaitables return successfully, or any awaitable raises (like gather)
  • any: returns when any awaitable returns successfully, or all awaitables raise
  • race: returns when any awaitable returns or raises

We should consider adding any and race, and aliasing gather as all.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Developer preview

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions