baml.spawn.Limit
Caps how many tasks spawned `with` it run at once.
Signature
class baml.spawn.LimitCaps 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_typeStatic methods
Creates a limit that admits capacity tasks at a time.
Throws
InvalidArgument if capacity is not positive.
Instance methods
active_count
(self) -> int throws neverHow many tasks hold a slot right now.
capacity
(self) -> int throws neverHow many tasks this limit admits at a time.
queued_count
(self) -> int throws neverHow many tasks are waiting for a slot right now.
Implementations
baml.Concrete for T
Source:<builtin>/baml/core.bamlbytes 763–795
baml.spawn.Modifier for baml.spawn.Limit
Output = TError = EApplyError = neverInstance methods
Source:<builtin>/baml/ns_spawn/spawn.bamlbytes 6451–6635