erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12.01k stars 2.5k forks source link

How to cansel Promise in `_ApiClient.js` #1268

Open alirezavalizade opened 7 years ago

alirezavalizade commented 7 years ago

Im Want When Route Changed, If any request is pending and Related to that component is destroying cansel it... example of cansel a promise :

//this promise has a way to stop what it is doing
var p1 = new Promise(function(resolve, reject, ignored){
  var task = setTimeout(resolve.bind(null, "the result"), 1000);
  ignored(() => clearTimeout(task));
});

//ignore the result from the above promise, triggers the ignored listener
p1.ignore();
p1.then(result => "this is never called");

//this promise cannot be cancelled, but the result can be ignored
var p2 = Promise.resolve("the result");

//the callback is not called until next event loop cycle
p2.then(result => "this is never called");

//the result is ignored, the above callback is never run
p2.ignore();

Im want somthing like this for all components and request.