Skip to content

Commit

Permalink
deps: co@4
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Jan 11, 2016
1 parent d851ab5 commit cd38c7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,5 +1,6 @@
language: node_js
node_js:
- '0.11'
- '4'
- '5'
script: "make test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
19 changes: 14 additions & 5 deletions index.js
Expand Up @@ -24,12 +24,12 @@ function wrap(emitter) {
var removeListener = emitter.removeListener;

emitter.on = emitter.addListener = function (type, listener) {
var wrapListener = listener;
var wrapped = listener;
if (listener.constructor.name === 'GeneratorFunction') {
wrapListener = co(listener);
listener.__coEventWrapListener = wrapListener;
wrapped = wrapListener(listener);
listener.__coEventWrapListener = wrapped;
}
on.call(emitter, type, wrapListener);
on.call(emitter, type, wrapped);
};

emitter.removeListener = function (type, listener) {
Expand All @@ -41,10 +41,19 @@ function wrap(emitter) {

emitter.once = function (type, listener) {
if (listener.constructor.name === 'GeneratorFunction') {
listener = co(listener);
listener = wrapListener(listener);
}
once.call(emitter, type, listener);
};

return emitter;
}

function wrapListener(listener) {
return function () {
var wrapped = co.wrap(listener);
wrapped.apply(null, arguments).then(noop);
};
}

function noop() {}
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -12,13 +12,13 @@
}
},
"dependencies": {
"co": "~3.1.0"
"co": "4"
},
"devDependencies": {
"autod": "*",
"contributors": "*",
"cov": "*",
"istanbul-harmony": "*",
"istanbul": "*",
"jshint": "*",
"mocha": "*",
"should": "~4.0.4"
Expand All @@ -37,7 +37,7 @@
"co-event-wrap"
],
"engines": {
"node": ">= 0.11.9"
"node": ">= 4"
},
"author": "fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)",
"license": "MIT"
Expand Down
12 changes: 12 additions & 0 deletions test/co-event-wrap.test.js
Expand Up @@ -115,4 +115,16 @@ describe('co-event-wrap.test.js', function () {
ev.listeners('data').should.length(0);
});
});

it('should error catched by promise', function(done) {
var ev = eventWrap(new EventEmitter());
ev.on('data', function* () {
throw new Error('error');
});
process.once('unhandledRejection', function (err) {
err.message.should.equal('error');
done();
});
ev.emit('data');
});
});

0 comments on commit cd38c7d

Please sign in to comment.