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