Skip to content

Commit 2ac0546

Browse files
author
Malte-Maurice Dreyer
committed
fixup! Make Promise Pool wrapper extend EventEmitter
1 parent ed6341a commit 2ac0546

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

promise.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ var core = require('./index.js');
22
var EventEmitter = require('events').EventEmitter;
33
var util = require('util');
44

5+
function inheritEvents(source, target, events) {
6+
events
7+
.forEach(function (eventName) {
8+
source.on(eventName, function () {
9+
var args = [].slice.call(arguments);
10+
args.unshift(eventName);
11+
12+
target.emit.apply(target, args);
13+
});
14+
});
15+
}
16+
517
function createConnection (opts) {
618
var coreConnection = core.createConnection(opts);
719
var Promise = opts.Promise || global.Promise;
@@ -171,17 +183,7 @@ function PromisePool(pool, Promise) {
171183
this.pool = pool;
172184
this.Promise = Promise;
173185

174-
['acquire', 'connection', 'enqueue', 'release']
175-
.forEach(function (eventName) {
176-
var t = this;
177-
178-
this.pool.on(eventName, function () {
179-
var args = [].slice.call(arguments);
180-
args.unshift(eventName);
181-
182-
t.emit.apply(t, args);
183-
});
184-
}, this);
186+
inheritEvents(pool, this, ['acquire', 'connection', 'enqueue', 'release']);
185187
}
186188
util.inherits(PromisePool, EventEmitter);
187189

test/integration/test-promise-wrappers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ var exceptionCaught = false;
2121

2222
var doneCalledPool = false;
2323
var exceptionCaughtPool = false;
24-
2524
var doneEventsPool = false;
2625

2726
function testBasic() {

0 commit comments

Comments
 (0)