register a handler block to fire whenever given event or task settles
Parameters
on target :task :event
action :block :bytecode
Attributes
| with |
:literal |
bind the emitted payload (or task result) to given symbol inside the handler |
| done |
|
with `:task`: fire only when the task ends successfully |
| failed |
|
with `:task`: fire only when the task ends with an error |
| cancelled |
|
with `:task`: fire only when the task ends by cancellation |
| finished |
|
with `:task`: fire on any termination (default) |
| id |
|
return an :integer id identifying this registration (for use with `off`) |
| once |
|
with `:event`: auto-remove the handler after its first fire |
Returns
Examples
copy
DataReady: event 'data-ready
on.with:'payload DataReady [ print ["got:" payload] ]
copy
on CtrlC [ print "graceful shutdown..." ]
copy
; task callbacks
t: do.async [pause 200 42]
on.done.with:'r t [ print ["ok:" r] ]
on.failed.with:'e t [ print ["fail:" e] ]
copy
on.once E [ print "fires once" ]
Related