I'm trying to do async/await style of programming using coffeescript and iced coffeescript.
What I get instead if 'undefined' response.
module.exports = update: (req, res) ->
await user = User.find({ id: 1 }).exec (err, user) ->
throw err if err?
console.log(err) # null
console.log(user) # object
defer user
console.log user # undefined
Your approach will not work because the iced-coffeescript syntax for
await, defer
is used slightly differently. See #icedYou have put
defer
into theawait
code block, but it is actually used a as callback forawait
.Edit: Callback function was missing.