亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

流星:在Meteor.method中調用異步函數并返回結果

流星:在Meteor.method中調用異步函數并返回結果

開滿天機 2019-10-09 15:50:15
我想在Meteor方法中調用異步函數,然后將結果從該函數返回給Meteor.call。(怎么)可能?Meteor.methods({  my_function: function(arg1, arg2) {    //Call other asynchronous function and return result or throw error  }});
查看完整描述

3 回答

?
江戶川亂折騰

TA貢獻1851條經驗 獲得超5個贊

對于這種情況,Meteor現在具有Meteor.wrapAsync()。


這是通過Stripe收費并傳遞回調函數的最簡單方法:


var stripe = StripeAPI("key");    

Meteor.methods({


    yourMethod: function(callArg) {


        var charge = Meteor.wrapAsync(stripe.charges.create, stripe.charges);

        charge({

            amount: amount,

            currency: "usd",

            //I passed the stripe token in callArg

            card: callArg.stripeToken,

        }, function(err, charge) {

            if (err && err.type === 'StripeCardError') {

              // The card has been declined

              throw new Meteor.Error("stripe-charge-error", err.message);

            }


            //Insert your 'on success' code here


        });

    }

});

查看完整回答
反對 回復 2019-10-09
  • 3 回答
  • 0 關注
  • 521 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號