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

Unexpected behavior when using bluebird Promise #50

Closed
alolis opened this issue Oct 13, 2018 · 1 comment
Closed

Unexpected behavior when using bluebird Promise #50

alolis opened this issue Oct 13, 2018 · 1 comment

Comments

@alolis
Copy link

alolis commented Oct 13, 2018

Hello,

I have noticed some weird behavior whenever I am using bluebird and async job handlers.

The following sample code will output a warning on the console:

import queue from 'queue';
import Promise from 'bluebird';

function createJobHandler(jobId) {
  return async function() {
    console.log(`Running handler for ${jobId}`);

    return jobId;
  }
}

function generateHandlers(numHandlers) {
  let counter = 1;
  let handlers = [];

  while (counter <= numHandlers) {
    handlers.push(createJobHandler(counter));
    counter++;
  }

  return handlers;
}

const jobsQueue = queue({concurrency: 1});

jobsQueue.on('error', (error) => {
  console.log("Error", error);
});

jobsQueue.on('success', (jobId, jobHandler) => {
  console.log(`Job ${jobId} completed!`);
});

jobsQueue.on('end', () => {
  console.log("All jobs completed");
});

const handlers = generateHandlers(2);
jobsQueue.push(...handlers);

jobsQueue.start();

The above will produce the following warning:

(node:36404) Warning: a promise was created in a handler at /myproject/node_modules/queue/index.js:145:7 but was not returned from it, see http://goo.gl/rRqMUw
    at new Promise (/myproject//node_modules/bluebird/js/release/promise.js:79:10)

An explanation of the above warning can be found here.

And the line from queue which triggers the warning is the following:

if (promise && promise.then && typeof promise.then === 'function') {
    promise.then(function (result) { // LINE 145  is here
      next(null, result)
    }).catch(function (err) {
      next(err || true)
    })
  }

If I remove the import Promise from 'bluebird' line however, everything will work normally.

Thank you for your time.

@jessetane
Copy link
Owner

I don't know Promises well, maybe @kwolfy can help?

jessetane added a commit that referenced this issue Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants