Skip to content

Thread Library

The @std/thread library allows spawning concurrent tasks.

  • spawn(function, ...args) — Runs a function asynchronously in a new thread.
  • The first argument must be a function.
  • The number and types of provided arguments must match the function’s expected parameters.
  • Executes the function concurrently without blocking the main thread.
  • Errors during execution are logged internally.
import thread from "@std/thread"
fn task(msg: string) -> void {
println(msg)
}
thread.spawn(task, "Hello from a thread!")