// Quick Reference ยง7: a bounded channel, every outcome handled (layer 7). // expect: run // grant: heap=mem.alloc:1024 // result: 5 // phase: 6 // spec: docs/agent/quick-reference.md module demo.qrchannels fn main(heap: cap) -> u64 effects [mem.alloc, task.wait] { let v = 5u64; var got: u64 = 0; match channel.make(2, heap) { // effect mem.alloc ok(tx, rx) => { let tx2 = channel.dup(tx); channel.close_sender(move tx2); match channel.send(tx, v) { ok => {} closed(v) => { trap; } cancelled(v) => { trap; } } // a linear v: `move v` match channel.recv(rx) { ok(v) => { got = v; } closed => { trap; } cancelled => { trap; } } channel.close_sender(move tx); match channel.close_receiver(move rx) { ok => {} pending(rx) => { trap; } } // drain, then close again } err(e) => { trap; } } got }