Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop UnhandledPromiseRejectionWarning/PromiseRejectionHandledWarning messages spamming #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

var slice = Array.prototype.slice;

/**
* Empty function to prevent unhandled Promise rejection warnings
*/

var noop = function() {};

/**
* Expose `co`.
*/
Expand Down Expand Up @@ -47,7 +53,7 @@ function co(gen) {
// we wrap everything in a promise to avoid promise chaining,
// which leads to memory leak errors.
// see https://github.com/tj/co/issues/180
return new Promise(function(resolve, reject) {
var promise = new Promise(function(resolve, reject) {
if (typeof gen === 'function') gen = gen.apply(ctx, args);
if (!gen || typeof gen.next !== 'function') return resolve(gen);

Expand Down Expand Up @@ -103,6 +109,8 @@ function co(gen) {
+ 'but the following object was passed: "' + String(ret.value) + '"'));
}
});
promise.catch(noop);
return promise;
}

/**
Expand Down Expand Up @@ -218,7 +226,7 @@ function isGenerator(obj) {
* @return {Boolean}
* @api private
*/

function isGeneratorFunction(obj) {
var constructor = obj.constructor;
if (!constructor) return false;
Expand Down