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