Improve result emit

This commit is contained in:
Mariusz Nowak
2016-07-05 17:13:29 +02:00
parent 01874cc639
commit e6e98853b5
2 changed files with 8 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
'use strict';
var aFrom = require('es5-ext/array/from')
, objectMap = require('es5-ext/object/map')
, mixin = require('es5-ext/object/mixin')
, defineLength = require('es5-ext/function/_define-length')
, nextTick = require('next-tick')
@@ -134,13 +135,15 @@ require('../lib/registered-extensions').async = function (tbi, conf) {
if (!cache[id]) return;
result = cache[id];
delete cache[id];
conf.emit('deleteasync', id, result);
conf.emit('deleteasync', id, slice.call(result.args, 1));
});
// On clear
conf.on('clear', function () {
var oldCache = cache;
cache = create(null);
conf.emit('clearasync', oldCache);
conf.emit('clearasync', objectMap(oldCache, function (data) {
return slice.call(data.args, 1);
}));
});
};

View File

@@ -6,14 +6,14 @@ var callable = require('es5-ext/object/valid-callable')
, forEach = require('es5-ext/object/for-each')
, extensions = require('../lib/registered-extensions')
, slice = Array.prototype.slice, apply = Function.prototype.apply;
, apply = Function.prototype.apply;
extensions.dispose = function (dispose, conf, options) {
var del;
callable(dispose);
if ((options.async && extensions.async) || (options.promise && extensions.promise)) {
conf.on('deleteasync', del = function (id, result) {
apply.call(dispose, null, slice.call(result.args, 1));
conf.on('deleteasync', del = function (id, resultArray) {
apply.call(dispose, null, resultArray);
});
conf.on('clearasync', function (cache) {
forEach(cache, function (result, id) { del(id, result); });