Javascript 在NodeJS中通过plivoapi发送批量短信

Javascript 在NodeJS中通过plivoapi发送批量短信,javascript,node.js,Javascript,Node.js,我把手机号码排成一列。 现在我正在循环浏览这些号码并发送短信。 我看到了这个例子,其中我们需要用“with”分隔数字,这在您希望等待多个承诺完成时非常有用 Doctor.getAllDoctorNumber(function(err, doc){ if(err) res.sendStatus(500); else { var sms = []; for(i=0;i<doc.length;i++) {

我把手机号码排成一列。 现在我正在循环浏览这些号码并发送短信。 我看到了这个例子,其中我们需要用“with”分隔数字,这在您希望等待多个承诺完成时非常有用

Doctor.getAllDoctorNumber(function(err, doc){
    if(err)
        res.sendStatus(500);
    else {
        var sms = [];
         for(i=0;i<doc.length;i++)
         {
            smo.push( sendSMS(doc[i], text));
         }
        Promise.all(sms).then(function() {
            console.log("all sms are sent");
        });         
    }
});
Doctor.getAllDoctorNumber(函数(err,doc){
如果(错误)
res.sendStatus(500);
否则{
var sms=[];

对于(i=0;iyou可以将所有sendSMS承诺推送到一个数组中,并使用promise.all并行解析所有承诺。
Doctor.getAllDoctorNumber(function(err, doc){
    if(err)
        res.sendStatus(500);
    else {
        var sms = [];
         for(i=0;i<doc.length;i++)
         {
            smo.push( sendSMS(doc[i], text));
         }
        Promise.all(sms).then(function() {
            console.log("all sms are sent");
        });         
    }
});