baml.spawn.Limit

Caps how many tasks spawned `with` it run at once.

Reference version

Signature

class baml.spawn.Limit

Caps how many tasks spawned with it run at once.

Tasks over the cap wait in line; the spawn still returns its Future at once. A waiting task can be cancelled. A task spawned with several limits starts once every one of them has room, and holds none of them while it waits. Two spawns share a cap only if they use the same Limit value, and a spawn that lists the same limit twice takes one slot.

Examples

let provider = baml.spawn.Limit.new(8);
let futures = ids.map((id) -> { spawn with provider { fetch(id) } });

Source:<builtin>/baml/ns_spawn/spawn.bamlbytes 5293–6058

Fields

_handle

$rust_type

Static methods

function

new

(capacity: int) -> baml.spawn.Limit throws baml.errors.InvalidArgument

Creates a limit that admits capacity tasks at a time.

Throws

InvalidArgument if capacity is not positive.

Instance methods

function

active_count

(self) -> int throws never

How many tasks hold a slot right now.

function

capacity

(self) -> int throws never

How many tasks this limit admits at a time.

function

queued_count

(self) -> int throws never

How many tasks are waiting for a slot right now.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 763–795