Skip to content

Instantly share code, notes, and snippets.

@mlsteele
Created November 5, 2018 16:14
Show Gist options
  • Save mlsteele/34394144a7a4751da1a8dbbff1f329bb to your computer and use it in GitHub Desktop.
Save mlsteele/34394144a7a4751da1a8dbbff1f329bb to your computer and use it in GitHub Desktop.
Return through esc multiple times
{make_esc} = require "iced-error"
bounce = (f) ->
setTimeout f, 0
f = ({ok}, cb) ->
bounce ->
console.log "f #{ok}"
if ok
cb null
else
cb new Error "fail"
main = (cb) ->
esc = make_esc cb
await
f {ok: true }, esc defer()
f {ok: false}, esc defer()
f {ok: false}, esc defer()
cb null
main (err) ->
if err?
console.log "err: #{err}"
else
console.log "ok"
f true
f false
err: Error: fail
f false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment