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
source to share
No one has answered this question yet
Check out similar questions: