function serializeAsynch(queue,operate) {
var msg = queue.dequeue();
if (msg) msg.then(function(data) { operate(data); serializeAsynch(queue); });
}
connect().then(function() { serializeAsynch(msgQueue,process); });
I think that will work. We're waiting for connect
to resolve, then passing in the msgQueue
. We get the first message in the queue
and set it's resolution handler to process the data and then recurse on the queue. The recursion will dump out when there's nothing left in the queue.