Rook
РусскийRU
// Channel objects do the same work as channel syntax and can be passed as functions.
const results = Channel.make(1, 0)
const received = Channel.receive(results)
await Channel.send(results, 42)
console.log(await received)
Channel.close(results)
move 8 of 8 · 1–0

Every result is received. The game is played.

Channel and Topic

Channel and Topic are predeclared objects with what channels and topics compile to, by name: Channel.make(size, zero), send, receive, close, range, select, try, fromStream, stream, after and tick; Topic.make(name, zero), publish, listen and close. They are for code that needs them as values, such as channels.forEach(Channel.close), and do what the syntax does without its checks: Channel.receive(ch) is a Promise of a ?T, and Topic.make does not check that the values can go to other tabs.

As the board grows, its task API can take these channel and topic operations as values wherever a callback is needed, while the rest of the app continues to use the concise channel and topic syntax.

Channel.EMPTY and Topic.EMPTY are the zero values of chan T and topic T, the same for all types, and they are closed: receiving gives the zero value of the type at once and ok is false, for over them ends at once, and what is sent to them goes nowhere. So let results chan number is safe to use before it gets a channel. In JS they are $$channels and $$topics of the runtime, so a program may declare Channel and Topic of its own.

// Channel and Topic have what channels and topics compile to, by name, and their zero values:
// Channel.EMPTY and Topic.EMPTY, which are closed
let none chan number // Channel.EMPTY
const n, ok = <-none // at once: 0, false
console.log("from EMPTY:", n, ok)

const lines = Channel.make(3, "") // chan<string>(3)
await Channel.send(lines, "one") // lines <- "one"
await Channel.send(lines, "two")
console.log("received:", await Channel.receive(lines)) // a ?string

// The functions are values: close every channel of a list
const channels = [lines, chan<string>(1)]
channels.forEach(Channel.close)
for line in lines {
    console.log("left after close:", line)
}

// A topic without a value is Topic.EMPTY: what is sent to it goes nowhere
let quiet topic string
quiet <- "nobody hears this"

const cart = Topic.make("guide-objects", 0) // topic<number>("guide-objects")
Topic.publish(cart, 1) // cart <- 1
const values = Topic.listen(cart) // a <-chan number, from now on
Topic.close(cart)
const last, open = <-values
console.log("after Topic.close:", last, open)