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

Static methods

function

type

() -> reflect.Type throws never

This type's runtime type value: int.type() is the same value as reflect.Type.of<int>().

Spell it on a declared type written as one name, optionally qualified or with generic arguments: Foo.type(), root.models.Base.type(), Box<int[]>.type(). Array, optional, union, map and function types, interfaces, and generic type parameters keep the reflect.Type.of<T>() form. A type that declares its own type member keeps resolving to it.

Source:<builtin>/baml/core.bamlbytes 1360–1392