needs lib/coop lib/struct drv/timer lib/time unit bench/coop extends Context struct IdlerContext { uint val limit ; } context IdlerContext bindstruct createapplication IdlerApp :> val limit < if doto val dup . 1+ | else stopcurrent then ; IDLE IdlerApp sethandler :> 0 to val ; INITIALIZE IdlerApp sethandler : idlerctx ( limit -- ctx ) IdlerApp newcontext 0 , swap , ; createapplication EchoApp EchoApp newcontext const echoctx :> evarg1 dup emit 'q' = if ."\nstopping EchoApp\n" stopcurrent then ; KEYPRESS EchoApp sethandler createapplication TimerApp extends Context struct TimerContext { uint periodms lastping ; smethod timercb ; } context TimerContext bindstruct :> periodms lastping elapsedms? if ticks to lastping timercb then ; IDLE TimerApp sethandler : timerctx ( xt period -- ctx ) TimerApp newcontext rot> , 0 , , ; createapplication AtApp extends Context struct AtContext { uint date ; smethod atcb ; } context AtContext bindstruct :> now date >= ctxstate RUNNING = and if stopcurrent atcb then ; IDLE AtApp sethandler : atctx ( xt time -- ctx ) AtApp newcontext rot> , , ; : .at ( ctx -- ) context[ ctxstate STOPPED = if ."executed at " else ."will execute at " then date .time nl> ]context ; :> context @ .at ; INITIALIZE AtApp sethandler