question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Would it be consistent in 3.0 to add static Promise.cancel() to return a new promise in cancelled state? (like Promise.resolve() and Promise.reject())

Promise.cancel = function() {
      var p = Promise(function(){});
      p.cancel();
      return p;
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:35 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
Artazorcommented, Apr 4, 2015

Even more surprising is that now

var a = request("A"); // from the previous example
var p = a.then(function(res) {
    console.log("fulfilled:", res);
    p.cancel(); // break the chain early
}).then(function() {
    console.log("Called")
});

produces

fulfilled: {body: "A"}

so the chain is broken.

But the same code with Promise.resolve({body: "A"})

var a = Promise.resolve({body: "A"});
var p = a.then(function(res) {
    console.log("fulfilled:", res);
    p.cancel(); // break
}).then(function() {
    console.log("Called")
});

produces:

fulfilled: {body: "A"}
Called

So the chain is not broken

O_o? (bye-bye mocked requests in unit/integration tests?) Worth it to be registered as a new issue?

1reaction
petkaantonovcommented, Apr 1, 2015

@benjamingr cancellation isn’t rejection with cancellation in 3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cancel a vanilla ECMAScript 6 Promise chain - Stack Overflow
Promise can be cancelled with the help of AbortController . Is there a method for clearing then: ...
Read more >
How to cancel a promise in javascript ? - DEV Community ‍ ‍
Promise cannot be cancelled, it is the process that returns promise must be cancellable. For example, XmlHttpRequest is cancellable as it has an ......
Read more >
You can already cancel ES6 Promises - gists · GitHub
The gist: by having a Promise adopt the state of a forever pending one, you can suspend its then handlers chain. Promise.pending =...
Read more >
Promise Cancellation Is Dead — Long Live ... - Ben Lesh
I want to be clear: You can't cancel a Promise. (I know, I know, mixed messages)… If something gives you a promise, your...
Read more >
How to Cancel That Embarrassing Email
Try canceling the promise before it gets a chance to start. You should see no countdown numbers at all: startCountingForHideAndSeek().cancel() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found