From 54fb4e4f1312b46e6ee9d43ba0806fdfff377e29 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 21 Sep 2012 13:47:48 +0200 Subject: [PATCH] async: safe purgeAll --- lib/ext/async.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ext/async.js b/lib/ext/async.js index 1d34b31..9403fc1 100644 --- a/lib/ext/async.js +++ b/lib/ext/async.js @@ -10,7 +10,7 @@ var toArray = require('es5-ext/lib/Array/from') , apply = Function.prototype.apply; require('../_base').ext.async = function (ignore, conf, options) { - var cache; + var cache, purge; cache = conf.async = {}; @@ -97,16 +97,17 @@ require('../_base').ext.async = function (ignore, conf, options) { }(conf.fn)); - conf.on('purge', function (id) { + conf.on('purge', purge = function (id) { // If false, we don't have value yet, so we assume that intention is not // to memoize this call. After value is obtained we don't cache it but // gracefully pass to callback if (!isArray(cache[id])) { + conf.emit('purgeasync', id); delete cache[id]; } }); conf.on('purgeall', function () { - cache = conf.async = {}; + forEach(conf.async, function (value, id) { purge(id); }); }); };