|
|
@ -60,14 +60,17 @@ Where `makeCancelable` is [defined by @istarkov](https://github.com/facebook/rea |
|
|
|
const makeCancelable = (promise) => { |
|
|
|
let hasCanceled_ = false; |
|
|
|
|
|
|
|
const wrappedPromise = new Promise((resolve, reject) => { |
|
|
|
promise.then((val) => |
|
|
|
hasCanceled_ ? reject({isCanceled: true}) : resolve(val) |
|
|
|
); |
|
|
|
promise.catch((error) => |
|
|
|
hasCanceled_ ? reject({isCanceled: true}) : reject(error) |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
return { |
|
|
|
promise: new Promise( |
|
|
|
(resolve, reject) => promise |
|
|
|
.then(r => hasCanceled_ |
|
|
|
? reject({isCanceled: true}) |
|
|
|
: resolve(r) |
|
|
|
) |
|
|
|
), |
|
|
|
promise: wrappedPromise, |
|
|
|
cancel() { |
|
|
|
hasCanceled_ = true; |
|
|
|
}, |
|
|
|