Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Meteor.wrapAsync时出错&引用;错误:Future解决了多次”;_Meteor - Fatal编程技术网

使用Meteor.wrapAsync时出错&引用;错误:Future解决了多次”;

使用Meteor.wrapAsync时出错&引用;错误:Future解决了多次”;,meteor,Meteor,我使用Meteor.wrapAsync包装我的标准node.js函数“sendMessage” 我使用循环调用Meteor.wrapAsync并执行sendMessageSync 但后来我发现了一个错误:“错误:未来不止解决一次” 为什么我会犯那个错误 这是我的密码: //Every 10 seconds get messages and send. Meteor.setInterval(function () { var messages = getMessagesFromDb();

我使用Meteor.wrapAsync包装我的标准node.js函数“sendMessage”

我使用循环调用Meteor.wrapAsync并执行sendMessageSync

但后来我发现了一个错误:“错误:未来不止解决一次”

为什么我会犯那个错误

这是我的密码:

//Every 10 seconds get messages and send.
Meteor.setInterval(function () {
    var messages = getMessagesFromDb();

    //Send message every two seconds.
    Meteor.setInterval(sendAllMessages, 2000);

    var i = 0;

    function sendAllMessages() {
        if (i++ < messages.length) {
            //Get the sync version of sendMessage.
            var sendMessageSync = Meteor.wrapAsync(sendMessage);

            var result = sendMessageSync('is4ags', messages[i - 1]);

            //Error:  "Exception in callback of async function: Error: Future resolved more than once"
            console.log('sendMessage response: ' + result);
        }
    }
}, 10000);

//sendMessage is standard node.js function that accept callback.
function sendMessage(toAddress, message, cb) {
    //sendMessage Implementations.
}
//每10秒获取消息并发送一次。
Meteor.setInterval(函数(){
var messages=getMessagesFromDb();
//每两秒钟发送一次信息。
Meteor.setInterval(sendAllMessages,2000年);
var i=0;
函数sendAllMessages(){
if(i++
您解决过这个问题吗?我有Meteor.clearInterval(),但我仍然得到这个错误。@Zacho是的,请看这个:。请看avital的回答。@Argus谢谢。我没有看到任何有用的答案,但我想我已经找到了答案。@Zacho在我的例子中,Fiber.return不止一次打电话给我。它发生在回调中的某个地方(在我的代码中,可能是sendMessage中的回调多次被解析)。@Agus使用Promise.all在此场景中。