✓
Passing This code compiles and runs correctly.
Code
// std/channel — the branch table is a vocabulary: `{ reading: Reading,
// alert: Alert }` is one channel firing either kind, one ring per kind.
// Sends name the kind (`send(wire, alert: a)`); consumers arm per kind.
import std/io
import std/proto
import std/channel
import std/pump
std/proto(Reading) {
id: u64
}
std/proto(Alert) {
level: u64
}
pub tor mk-reading { i: u64 } -> Reading
mk-reading -> { id: i }
pub tor mk-alert { l: u64 } -> Alert
mk-alert -> { level: l }
std/channel:new(wire, capacity: 8) { reading: Reading, alert: Alert }
std/channel(wire)
! reading v |> std/io:print.ln("reading {{ v.id:d }}")
std/channel(wire)
! alert a |> std/io:print.ln("alert {{ a.level:d }}")
mk-reading(i: 1): r |> std/channel:send(wire, reading: r)
| ok |> mk-alert(l: 7): a |> std/channel:send(wire, alert: a)
| ok |> std/channel:close(wire)
| ok |> std/io:print.ln("sealed")
| full |> std/io:print.ln("full2")
| closed |> std/io:print.ln("closed2")
| full |> std/io:print.ln("full1")
| closed |> std/io:print.ln("closed1")
std/pump:create(main)
| drained |> std/io:print.ln("pump drained")
std/pump(main)
! step |> wire-step()
! live |> wire-live()
std/pump:run(main)
Actual
sealed
reading 1
alert 7
pump drained
Expected output
sealed
reading 1
alert 7
pump drained
Flows
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Reading, source: id: u64)
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Alert, source: level: u64)
flow ~new click a branch to expand · @labels scroll to their anchor
new (expr: wire, capacity: 8, source: reading: Reading, alert: Alert)
flow ~std/channel click a branch to expand · @labels scroll to their anchor
std/channel (wire)
flow ~std/channel click a branch to expand · @labels scroll to their anchor
std/channel (wire)
flow ~mk-reading click a branch to expand · @labels scroll to their anchor
mk-reading (i: 1)
flow ~create click a branch to expand · @labels scroll to their anchor
create (expr: main)
flow ~std/pump click a branch to expand · @labels scroll to their anchor
std/pump (main)
flow ~run click a branch to expand · @labels scroll to their anchor
run (main)
Test Configuration
MUST_RUN