From 02f51ad0dfa8bc670f51aa166072fdecde2751d6 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sun, 27 Oct 2013 11:13:11 -0400 Subject: [PATCH] Split creating the defer and returning the promise --- js/websockets.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/websockets.js b/js/websockets.js index 534941f..5a731cc 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -196,7 +196,7 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers', var callbacks = {} var currentCallBackId = 0; - var doSendWithCallback = function(message) { + var createCallback = function(message) { var defer = $q.defer(); callbacks[++currentCallBackId] = { time: new Date, @@ -204,7 +204,12 @@ weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers', } callBackIdString = "(" + currentCallBackId + ")"; doSend(callBackIdString + " " + message); - return defer.promise; + return defer; + } + + var doSendWithCallback = function(message) { + var cb = createCallback(message); + return cb.promise; } // Sanitizes messages to be sent to the weechat relay