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.CancelTokenA 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 3763–4662
Fields
_handle
$rust_typeStatic methods
function
any
(tokens: baml.spawn.CancelToken[]) -> baml.spawn.CancelToken throws neverfunction
new
() -> baml.spawn.CancelToken throws neverInstance methods
function
cancel
(self) -> int throws neverfunction
is_cancelled
(self) -> bool throws neverImplementations
baml.Concrete for T
Source:<builtin>/baml/core.bamlbytes 747–779