Goroutines on real threads
go f(x) runs a function in a pool of Web Workers or worker threads, one per processor, and gives a Promise of its result. No worker files, no messages written by hand.
const n = await go countPrimes(0, N)
Rook is a language with the semantics of JavaScript, the syntax of Go and static types. The word go runs a function on another processor, channels connect the goroutines, and it all compiles to readable JavaScript.
npm install rooklang<-results: main meets square 1, who was waiting, and takes 1.
go for splits an array into parts, several per processor, runs each part as a goroutine on the first free core and waits for all of them. The same loop, one word longer.
8.1×faster
primes is an array of ten million numbers. Each one has to be checked.
for i, _ in primes { primes[i] = isPrime(i) ? 1 : 0 }
one thread0 ms
go for i, _ in primes { primes[i] = isPrime(i) ? 1 : 0 }
every core0 ms
Open in playgroundMeasured with Node on a machine with 14 cores: a rook for each core where the screen has the room.
Threads, channels and types that know about them, in a language that compiles to plain JavaScript for the browser and Node.
go f(x) runs a function in a pool of Web Workers or worker threads, one per processor, and gives a Promise of its result. No worker files, no messages written by hand.
const n = await go countPrimes(0, N)
Goroutines in any thread pass values through channels, wait on several at once and stop waiting with after(ms), as in Go.
select {case msg = <-messages: console.log(msg)case <-after(500): console.log("timeout")}Watch it move by move
A function, a class or a DOM element cannot be copied to another thread. The compiler says so before the program runs.
main.rk:3:9: error: the goroutine runs in a worker, which gets a copy of "title", but a copy of HTMLElement would lose its methods
comp, state and markup compile to direct calls of the DOM, without a virtual DOM. This counter is a component of this page:
state count = 0 <button onClick={count++}>
The same markup writes a server: there it is a string of HTML, a component is an async function, and the root answers a request. Experimental until 1.0.
comp Page(request Request) { const user = await currentUser(request) return <h1>Hello, {user.name}</h1> } serve(Page, { port: 3000 })
A CLI that builds and runs, a Vite plugin, an extension for VS Code with errors as you type and completion, and .d.ts files for TypeScript.
Each construct becomes the JavaScript you would write by hand. What channels and goroutines need comes from a small runtime, imported by name.
The compiler is an npm package and runs on Node.js 24.
1Install
$ npm install rooklang2Write
func greet(name string) string { return `Hello, ${name}!` } console.log(greet("Rook"))
3Run
$ npx rook run hello.rk Hello, Rook!
From variables to goroutines and components, with examples you can run right on the page.