Skip to content

Instantly share code, notes, and snippets.

@summivox
Created February 10, 2013 23:49
Show Gist options
  • Save summivox/4751579 to your computer and use it in GitHub Desktop.
Save summivox/4751579 to your computer and use it in GitHub Desktop.
# mock-up async for test in browser
readfile=(file, cb)->
setTimeout (->
console.log("readfile(#{file}) callback")
cb(null, file+'data')
), 500
parse=(data, cb)->
setTimeout (->
console.log("parse(#{data}) callback")
cb(data, data.charCodeAt(0))
), 100
# actual code
fileArray=['a', 'b', 'c']
dict={}
await
for file in fileArray
((file, autocb)->
# autocb keyword: "return means callback"
await readfile file, defer(err, data)
await parse data, defer(k, v)
dict[k]=v
)(file, defer())
console.log JSON.stringify dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment