// Capacity 0: every send completes only when the receiver takes the value. // expect: run // grant: heap=mem.alloc:64 // schedules: 20 // quantum: 2 // result: 6 // equivalent: phase3/run/channels_rendezvous.air // phase: 6 // spec: docs/spec/15-source-language.md module demo.rendezvous fn produce(tx: sender) -> u8 effects [task.wait] { var i: u64 = 1; while i != 4 { match channel.send(tx, i) { ok => {} closed(w) => { break; } cancelled(w) => { break; } } i = i + 1; } channel.close_sender(move tx); 0 } fn main(heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] { match channel.make(0, heap) { ok(tx, rx) => { var acc: u64 = 0; scope sc { let t = task.spawn(sc, produce, move tx); var r: receiver = move rx; loop { match channel.recv(r) { ok(v) => { acc = acc + v; } closed => { match channel.close_receiver(move r) { ok => { break; } pending(r) => {} } } cancelled => { match channel.close_receiver(move r) { ok => { break; } pending(r) => {} } } } } let x = task.join(move t); } acc } err(e) => { trap; } } }