baml.spawn.CancelToken

A one-shot cancellation handle backed by a runtime cancellation token. Passing one via `options(cancel = ...)` links it into a spawned task's effective token: once fired, the task's next `await` panics with `baml.panics.Cancelled`. Once cancelled, a token stays cancelled forever.

Reference version

Signature

class baml.spawn.CancelToken

A one-shot cancellation handle backed by a runtime cancellation token. Passing one via options(cancel = ...) links it into a spawned task's effective token: once fired, the task's next await panics with baml.panics.Cancelled. Once cancelled, a token stays cancelled forever.

Examples

let token = baml.spawn.CancelToken.new()
spawn with baml.spawn.options(cancel = token) {
    baml.sys.sleep(baml.time.Duration.from_seconds(5)); // cancellation triggers here inside `sleep`
    baml.io.println("sleep finished");
}
token.cancel();

Source:<builtin>/baml/ns_spawn/spawn.bamlbytes 37634662

Fields

_handle

$rust_type

Static methods

function

any

(tokens: baml.spawn.CancelToken[]) -> baml.spawn.CancelToken throws never
function

new

() -> baml.spawn.CancelToken throws never

Instance methods

function

cancel

(self) -> int throws never
function

is_cancelled

(self) -> bool throws never

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 747779