From 69edaa2159c8bc3a98a9000524d12dbf68f6c158 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 4 Oct 2014 13:15:18 +0200 Subject: [PATCH] Changed promises to use IDs --- public_html/js/Promise.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public_html/js/Promise.js b/public_html/js/Promise.js index aef732fc..edbdb7c1 100644 --- a/public_html/js/Promise.js +++ b/public_html/js/Promise.js @@ -3,26 +3,28 @@ var App = App || {}; App.Promise = function(_, jQuery) { var active = []; + var promiseId = 0; function make(callback) { var deferred = jQuery.Deferred(); var promise = deferred.promise(); + promise.promiseId = ++ promiseId; callback(function() { deferred.resolve.apply(deferred, arguments); - active = _.without(active, promise); + active = _.without(active, promise.promiseId); }, function() { deferred.reject.apply(deferred, arguments); - active = _.without(active, promise); + active = _.without(active, promise.promiseId); }); promise.then(function() { - if (!_.contains(active, promise)) { + if (!_.contains(active, promise.promiseId)) { throw new Error('Broken promise'); } }); - active.push(promise); + active.push(promise.promiseId); return promise; }