Skip to content

Commit

Permalink
Merge pull request facebook#6152 from jimfb/fix-blog-code-fragment
Browse files Browse the repository at this point in the history
Updated code fragment for correctness.
  • Loading branch information
jimfb committed Mar 1, 2016
2 parents 4da7e7e + aec8a9b commit 56c423a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions docs/_posts/2015-12-16-ismounted-antipattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 56c423a

Please sign in to comment.