Error while using Meteor.wrapAsync. "Error: the future is resolved more than once"

I am using Meteor.wrapAsync to wrap my standard node.js "sendMessage" function.

And I am using looping to call Meteor.wrapAsync and execute sendMessageSync.

But then I got the error: "Error: the future is resolved more than once"

Why did I get this error?

Here is my code:

//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.
}

      

+3
meteor


source to share


No one has answered this question yet

Check out similar questions:

7
Meteor: When is it. Is simulation more useful than Meteor.isClient?
five
Meteor wrapAsync runs synchronously but never returns
3
Meteor: customize error messages from allow and deny rules
2
Meteor how to wait on callback before dispatching Redux action
1
How do I handle errors in Meteor.wrapAsync?
1
Blaming MongoDB Calls in Promise
1
Exception in async function callback: Error: Future resolved more than once
1
Meteor how to use Meteor.wrapAsync with facebook Graph Api
0
Multiple Meteor.wrapAsync functions at once
0
Meteor.wrapAsync not working



All Articles
Loading...
X
Show
Funny
Dev
Pics