asynchronous - Meteor async function in method -
i read concerning issue , must admit still pretty lost.
i have payment system need http post queries validate payment.
so here code on server:
payment.sendpayment = function(callback){ http.post(..., function(err, result){ if(err) throw new error('this error!'); callback && callback(null); }); }
with method follow:
meteor.methods({ buy: function(){ payment.sendpayment(function(err){ if(err) throw new meteor.error('buy', err); }); } });
it not work since return not in main function. tried wrapasync:
meteor.methods({ buy: function(){ var sendpayment = meteor.wrapasync(payment.sendpayment); console.log(sendpayment()); } });
still not work. couldn't find simple example of wrapasync. found stuff concerning future package posts quite old.
any idea this?
thank you!
if want use futures, here example:
var future = npm.require('fibers/future'); meteor.methods({ buy: function(){ var future = future(); payment.sendpayment(function(err){ if(err) { return future.return(err); //return error } return future.return(); //you can return result here if want }); return future.wait(); } });
Comments
Post a Comment