async: safe purgeAll

This commit is contained in:
Mariusz Nowak
2012-09-21 13:47:48 +02:00
parent d23505d700
commit 54fb4e4f13

View File

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