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); }); }); };