Whichever, timers, structured tasks, a task that fails.
whichever.zg
# whichever, timers, structured tasks, a task that fails (design/concurrency.md, 2026-09-22).fnfetch[lent'url':str.utf8]->str.utf8orfail[no_network]{if'url'equal_to"down.com"{failno_network;}return"page of "++'url';}MAIN{let'inbox':=channel[str.utf8][max10];let'shutdown':=channel[bool];concurwith[lend'inbox']{channel.send[lend'inbox',value"first"];channel.send[lend'inbox',value"second"];}concurwith[lend'shutdown']{channel.send[lend'shutdown',valuetrue];}let'deadline':=std::time.after[5seconds];for'i'from1to4by1{whichever{'msg'fromlend'inbox'{std::print.useful["got ",'msg',newln];}'why'fromlend'shutdown'{std::print.useful["shutdown",newln];}'now'fromlend'deadline'{std::print.useful["timed out after ",'now',newln];}}otherwise{closed{std::print.useful["all closed",newln];}};}{concur{std::print.useful["task in a block",newln];}std::print.useful["block body",newln];}std::print.useful["after the block",newln];concurwith[lend'inbox']{let'p':=fetch["down.com"]otherwisefail;channel.send[lend'inbox',valuegive'p'];}otherwise{no_network{std::print.useful["offline",newln];}};let'tick':=std::time.every[1second];let't':=channel.take[lend'tick']otherwise0seconds;std::print.useful["tick ",'t',newln];}
Output
got first
got second
shutdown
timed out after 5 seconds
block body
task in a block
after the block
offline
tick 1 second