Concurrent function calls
We’ll use function ClassifyMessage(input: string) -> Category
for our example:
classify-message.baml
Python
TypeScript
Go
Ruby (beta)
You can make concurrent b.ClassifyMessage()
calls like so:
Cancelling Parallel Operations
When running multiple operations in parallel, you can use abort controllers to cancel them all at once or individually.
Cancel All Operations
Use a single abort controller to cancel all parallel operations:
TypeScript
Python
Go
Cancel Individual Operations
Use separate controllers to cancel operations independently:
TypeScript
Python
Fastest Request Wins
Race multiple LLM providers and cancel slower ones when the fastest completes. This pattern is useful for optimizing latency by using whichever provider responds first.
TypeScript
Python
Go
Implementing Timeouts for Parallel Operations
Set automatic timeouts to prevent operations from running indefinitely:
TypeScript
Python
Go
Batching with Cancellation Support
Process items in batches with the ability to cancel remaining batches:
TypeScript
Python
For basic abort controller usage and error handling, see the Abort Controllers guide.