We talked earlier about using Promise.race to implement a timeout mechanism to cancel XHR requests. Now let’s look at a simple, fun, and practical way to control Promise behavior by assigning the resolve and reject functions to variables. Direct up code

var rejectPromise,resolvePromise;
new Promise((resolve,reject)=>{
  rejectPromise = reject;
  resolvePromise = resolve;
}).then(res=>{console.log('success')}).catch(res=>{console.log('fail')})

With rejectPromise, resolvePromise, we can control the Promise anywhere. Of course, by executing either rejectPromise or resolvePromise, the state of the Promise object will already have changed, and by using rejectPromise or resolvePromise it will not change the state of the Promise. No callbacks will be executed