Skip to content

Instantly share code, notes, and snippets.

@jots
Created November 9, 2013 05:44
Show Gist options
  • Save jots/7382177 to your computer and use it in GitHub Desktop.
Save jots/7382177 to your computer and use it in GitHub Desktop.
icedcoffeescript question
# can await be made to not return from function until it is done?
fs = require("fs")
readfile = (fn) ->
await fs.readFile fn, "utf8", defer(err,res)
#console.log "res: ", res
return res
a = readfile("dbtest.coffee")
console.log a # a is undefined
@maxtaco
Copy link

maxtaco commented Nov 10, 2013

Turtles all the way up:

fs = require("fs")
readfile = (fn, cb) ->
  await fs.readFile fn, "utf8", defer(err,res)
  #console.log "res: ", res
  cb err, res

await readfile "dbtest.coffee", defer err, a
console.log a # a is undefined

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