Implement doSendAllWithCallback

doSendAllWithCallback sends all the messages of the list
and returns a promise that is resolved when all the individual
promises are resolved.

Useful for avoiding long chains of .then().then().then() ..
This commit is contained in:
David Cormier 2013-10-27 11:28:34 -04:00
parent 02f51ad0df
commit ec4956a379

View file

@ -212,6 +212,23 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers',
return cb.promise; return cb.promise;
} }
/*
* Send all messages to the websocket and returns a promise that is resolved
* when all message are resolved.
*
* @param messages list of messages
* @returns a promise
*/
var doSendAllWithCallback = function(messages) {
var promises = [];
for(i in messages) {
var cb = createCallback(messages[i]);
promises.push(cb.promise);
};
return $q.all(promises);
};
// Sanitizes messages to be sent to the weechat relay // Sanitizes messages to be sent to the weechat relay
var doSend = function(message) { var doSend = function(message) {
msgs = message.replace(/[\r\n]+$/g, "").split("\n"); msgs = message.replace(/[\r\n]+$/g, "").split("\n");