Created
October 26, 2017 07:07
-
-
Save marlun78/e0a24441e00a69b626606c58f02256c8 to your computer and use it in GitHub Desktop.
An idea for promise cancelation (it doesn’t really cancel the promise, just make sure it never resolves or rejects)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an idea, completely untested! | |
function makeCancelable(promise) { | |
let canceled = false; | |
const proxy = new Promise((resolve, reject) => { | |
promise.then( | |
(value) => canceled === false && resolve(value), | |
(error) => canceled === false && reject(error) | |
); | |
}); | |
proxy.cancel = () => canceled = true; | |
return proxy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment