我一直在努力工作Meteor.WrapAsync
我已閱讀Meteor wrapAsync syntax回答,這個視頻https://www.eventedmind.com/feed/meteor-meteor-wrapasync和我只是無法計算如何return
來自Stripe調用的響應。我用console.log
來打印這些步驟,並且我已經到達了第4個擲數,這意味着,我到達stripe
服務器並獲得響應,但之後我看不到爲什麼console.log(5)
它沒有打印。請如果有人能幫我理解爲什麼它的wrapAsyn它不返回條紋回調?Meteor.WrapAsync不返回值
//this functions are part of an anonymous function and running in the server side of meteor
stripe.charge = function (stripeToken) {
// get a sync version of our API async func
var strypeChargeSync = Meteor.wrapAsync(stripe.charge.process);
// call the sync version of our API func with the parameters from the method call
console.log("1");
var response = strypeChargeSync(stripeToken);
console.log("5" + response); ///// this never get print/log
return response;
}
stripe.charge.process = function(stripeToken){
var _stripe = StripeAPI(stripeKey);
console.log("2");
var charge = _stripe.charges.create({
amount: 1000, // amount in cents, again
currency: "cad",
card: stripeToken.id,
description: "[email protected]"
}, function(err, charge) {
if (err && err.type === 'StripeCardError') {
alert("Sorry we couldn't charge the money: " + err);
//console.log(err);
}else{
console.log("4");
//console.log(charge);
return charge;
}
});
console.log("3");
}
//電流輸出1,2,3,4,但從來沒有5 :(
編輯
這是我結束具有條紋功能感謝支持
var syncFunction = Meteor.wrapAsync(_stripe.charges.create, _stripe.charges);
var response = syncFunction({
amount: 1000, // amount in cents, again
currency: "cad",
card: stripeToken.id,
description: "[email protected]"
});
控制檯中的任何錯誤?我猜想會發生這種情況,因爲你沒有將函數綁定到對象上:'Meteor.wrapAsync(stripe.charge.process,stripe.charge)' – imslavko 2014-10-12 21:01:42
沒有任何錯誤,並且在一開始就做到了這一點讓我試試吧現在再次... – ncubica 2014-10-12 21:22:59