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

Unable to cancel promise (Node.js) #1665

Open
fider-apptimia opened this issue Dec 2, 2020 · 3 comments
Open

Unable to cancel promise (Node.js) #1665

fider-apptimia opened this issue Dec 2, 2020 · 3 comments

Comments

@fider-apptimia
Copy link

fider-apptimia commented Dec 2, 2020

  1. What version of bluebird is the issue happening on?
    "bluebird": "^3.7.2",
    "@types/bluebird": "^3.5.33",

  2. What platform and version?
    Using ts-node version 8.10.2, typescript version 3.9.5
    node v12.18.4

  3. Did this issue happen with earlier version of bluebird?
    No idea.

  4. Reproduce

import P = require('bluebird');

P.config({
  cancellation: true,
});

async function go() {
  setTimeout(() => {}, 5000); // keep alive

  console.log('start');

  const p = new P((resolve: any, reject: any, onCancel: any) => {
    const to = setTimeout(() => resolve(), 2000);

    onCancel(() => {
      console.log('onCancel called');
      clearTimeout(to);
      reject(new Error('cancel')); // no error throwed. With resolve() in this place it also hangs on await
    });
  });

  setTimeout(() => p.cancel(), 1000);

  await p;

  console.log('end');
}

go();

Actual output:

start
onCancel called

Expected output:

start
onCancel called
end
@benjamingr
Copy link
Collaborator

Promise cancellation probably just doesn't work with async/await well?

It makes sense with third-state cancellation that end isn't called.

@bergus
Copy link
Contributor

bergus commented Dec 3, 2020

You're rejecting the promise. Why would you expect end to still be called?

@fider-apptimia
Copy link
Author

@bergus it is not working neither with resolve nor with reject - it just hangs on await in both cases.
(btw. reject without try/catch should throw and here nothing happens)

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

3 participants