#1718·bluebird

Directly accessing isCancelled when declaring variables, it returns false

Author: JackWang032Created Nov 18, 2024Updated Nov 18, 2024

(This issue tracker is only for bug reports or feature requests, if this is neither, please choose appropriate channel from http://bluebirdjs.com/docs/support.html)

Please answer the questions the best you can:

  1. What version of bluebird is the issue happening on? 3.7.2
  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32) Chrome 130.0.6723.70
  3. Did this issue happen with earlier version of bluebird? 3.x (Write description of your issue here, stack traces from errors and code that reproduces the issue are helpful)

it works right if cancel the root promise

let p = CancellablePromise.delay(1000).finally(() => {
  console.log(p.isCancelled())
});
p.cancel();
// print true

if you declare another promise instance, you must access the isCancelled state asynchronously.

let p = CancellablePromise.delay(1000);
let p1 = p.then().finally(() => {
    console.log('a:', p1.isCancelled());
    setTimeout(() => {
        console.log('b:', p1.isCancelled());
     }, 0)
})
p.cancel();

// print a: false,  b: true