Created
February 10, 2013 23:49
-
-
Save summivox/4751579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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