Colorless Async & Concurrency
SPL eliminates function coloring — there are no async or await keywords in user code.
How Colorless Async Works
Section titled “How Colorless Async Works”The compiler performs fixed-point effect inference across the call graph:
- Pure functions compile to plain synchronous JavaScript functions with zero
Promiseoverhead. - Any function that transitively calls a suspending operation (
http.fetch,fs.read,clock.sleep,llm.ask, etc.) automatically compiles to a JSasync functionwithawaitinserted at call sites.
import clock from "std/clock"
// Pure -> compiled to synchronous JSfn double(n: Int) -> Int { n * 2}
// Calls `clock.sleep` -> compiler infers async automatically!fn slow_double(n: Int) -> Int { clock.sleep(25) double(n)}Sequential by Default, Concurrent by Choice
Section titled “Sequential by Default, Concurrent by Choice”To prevent agentic code from accidentally spawning unbounded parallel LLM or tool requests, Array.map runs sequentially by default. Concurrency is always explicit and opt-in:
// Sequential (~75ms): runs one item after anotherlet seq = [1, 2, 3].map { x -> slow_double(x) }
// Concurrent (~25ms): runs all items via `Promise.all`let par = [1, 2, 3].par_map { x -> slow_double(x) }
// Explicit combinatorslet both = async_all([ { -> slow_double(10) }, { -> slow_double(20) }])
let fastest = async_race([ { -> clock.sleep(50); "slow" }, { -> clock.sleep(5); "fast" }])