def producer sink:&:sink:char -> sink:&:sink:char [
local-scope
load-ingredients
n:char <- copy 0
{
done?:boolean <- lesser-than n, 5
break-unless done?
$print [produce: ], n, [
]
sink <- write sink, n
n <- add n, 1
loop
}
close sink
]
def consumer source:&:source:char -> source:&:source:char [
local-scope
load-ingredients
{
n:char, eof?:boolean, source <- read source
break-if eof?
$print [consume: ], n:char, [
]
loop
}
]
def main [
local-scope
source:&:source:char, sink:&:sink:char <- new-channel 3/capacity
routine1:num <- start-running producer, sink
routine2:num <- start-running consumer, source
wait-for-routine routine1
wait-for-routine routine2
]