MCPcopy Create free account
hub / github.com/crazycodeboy/GitHubPopular / makeCancelable

Function makeCancelable

js/util/Cancelable.js:7–24  ·  view source on GitHub ↗
(promise)

Source from the content-addressed store, hash-verified

5'use strict'
6
7export default function makeCancelable(promise){
8 let hasCanceled_ = false;
9 const wrappedPromise = new Promise((resolve, reject) => {
10 promise.then((val) =>
11 hasCanceled_ ? reject({isCanceled: true}) : resolve(val)
12 );
13 promise.catch((error) =>
14 hasCanceled_ ? reject({isCanceled: true}) : reject(error)
15 );
16 });
17
18 return {
19 promise: wrappedPromise,
20 cancel() {
21 hasCanceled_ = true;
22 },
23 };
24}

Callers 1

loadDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected