eventemitter-ex
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -278,2 +278,12 @@ 'use strict'; | ||
EventEmitterEx.fromPromiseFunc = function fromPromiseFunc (f) { | ||
var eex = new EventEmitterEx(); | ||
setImmediate(function () { | ||
f(eex).then(eex.emit.bind(eex, 'end'), eex.emit.bind(eex, 'error')); | ||
}); | ||
return eex; | ||
}; | ||
function assertIsFunction (f) { | ||
@@ -280,0 +290,0 @@ if (typeof f !== 'function') |
{ | ||
"name": "eventemitter-ex", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "EventEmitter extensions", | ||
@@ -31,3 +31,3 @@ "main": "EventEmitterEx.js", | ||
"author": "Mikhail Mazurskiy <mikhail.mazursky@gmail.com> (ash2k.com)", | ||
"license": "Apache 2", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
@@ -34,0 +34,0 @@ "chai": "2.x.x", |
@@ -98,2 +98,48 @@ 'use strict'; | ||
describe('#fromPromiseFunc()', function () { | ||
it('should emit end when promise is resolved', function (done) { | ||
var eex = EEX.fromPromiseFunc(function () { | ||
return Promise.resolve(42); | ||
}); | ||
eex | ||
.on('end', function (res) { | ||
res.should.equal(42); | ||
done(); | ||
}) | ||
.on('error', done); | ||
}); | ||
it('should emit error when promise is rejected', function (done) { | ||
var ERROR = new Error('Boom!'); | ||
var eex = EEX.fromPromiseFunc(function () { | ||
return Promise.reject(ERROR); | ||
}); | ||
eex | ||
.on('error', function (err) { | ||
err.should.equal(ERROR); | ||
done(); | ||
}) | ||
.on('end', function () { | ||
done(new Error('WTF?')); | ||
}); | ||
}); | ||
it('should pass emitter as argument', function (done) { | ||
var A = 34; | ||
var eex = EEX.fromPromiseFunc(function (em) { | ||
em.emit('data', A); | ||
return Promise.resolve(42); | ||
}); | ||
eex | ||
.on('data', function (a) { | ||
a.should.be.equal(A); | ||
done(); | ||
}) | ||
.on('error', done); | ||
}); | ||
}); | ||
}); | ||
@@ -100,0 +146,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60008
986