Skip to content

Instantly share code, notes, and snippets.

@Artazor
Created November 5, 2013 16:05
Show Gist options
  • Save Artazor/7321358 to your computer and use it in GitHub Desktop.
Save Artazor/7321358 to your computer and use it in GitHub Desktop.
Any chances to make such syntax/semantics consistent? Can we allow multiple unwinds 1) per defer 2) dynamically per await (eg in await for-loops) 3) statically per await
someFunc = (x,y,z, cb) ->
await check x, defer err, res_x
return cb err if err
await check x, defer err, res_y
return cb err if err
await check x, defer err, res_z
return cb err if err
cb null, res_x + res_y + res_z
# PROPOSAL: "unwinding defers"
# use
#
# await f defer cb(err), res
#
# as short syntax for
#
# await f defer err, res
# return cb err if err
#
someFunc2 = (x,y,z, cb) ->
await check x, defer cb(err), res_x
await check x, defer cb(err), res_y
await check x, defer cb(err), res_z
cb null, res_x + res_y + res_z
@maxtaco
Copy link

maxtaco commented Nov 5, 2013

Here's the way I deal with this. Cheers.

{make_esc} = require 'iced-error'

someFunc3 = (x,y,z,cb) ->
  esc = make_esc cb, "Error Short Circuiter for someFunc3"
  await check x, esc defer res_x
  await check y, esc defer res_y
  await check z, esc defer res_z
  cb null, res_x + res_y + res_z

@Artazor
Copy link
Author

Artazor commented Nov 5, 2013

Thanks a lot! Just what I needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment