I have the following asynchronous Meteor method. However, createItem()
is not waiting for Items.insert
's callback to fire before returning.
# Relevant pieces shown here (coffeescript, more parens than usual for js folks :-)
Meteor.methods(
createItem : (doc, callback)->
asyncInsert = Meteor.wrapAsync( Items.insert, Items )
results = asyncInsert( doc, (err, result) ->
return callback(err, result)
)
return results
)
asyncMeteorCall = Meteor.wrapAsync( Meteor.call )
status = asyncMeteorCall( "createItem", {name:"some item"}, (err, result)->
if err?
return "Error adding Item"
else
return "Successfully added Item"
)
console.log( status ) # prints : undefined
I did find this possibly related issue, but not sure if it's relevant, I'm actually doing all of the above on the server.