如何包装这个特定的功能?

时间:2016-01-11 20:58:07

标签: javascript node.js meteor

  connection.query(selectMailgunChecked, function(err, rows){
    if (err) throw err;
    var emails = rows.map(function(a) {return a.email});
    var from = 'sample@email.com';
    emails.forEach(function sort(entry){
        mailgunSend(entry,from,contentHTML,contentRAW,subject,tags);
    });
  });

我在我的流星应用程序中使用此程序包(由https://atmospherejs.com/meteorhacks/npm安装) - https://github.com/felixge/node-mysql/

以上代码无法运行,在运行应用时出现错误 - "无法等待光纤"。我想我必须使用wrapp函数(错误,行),但我该怎么做呢?我在网上找到的教程并没有真正解决我的问题。

2 个答案:

答案 0 :(得分:1)

您可能只需要包装connection.query函数。

var sync = Meteor.wrapAsync(connection.query);
var rows = sync(selectMailgunChecked);
var emails = rows.map(function(a) {
     return a.email
});
var from = 'sample@email.com';
emails.forEach(function(entry) {
    mailgunSend( entry, from, contentHTML, contentRAW, subject, tags);
});

答案 1 :(得分:0)

var sync = Meteor.wrapAsync(connection.query, connection);
var rows = sync(selectMailgunChecked);
var emails = rows.map(function(a) {
     return a.email
});
var from = 'sample@email.com';
emails.forEach(function(entry) {
    mailgunSend( entry, from, contentHTML, contentRAW, subject, tags);
});

此代码处理TypeCast属性的错误。

相关问题