real-cancellable-promise
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -1,7 +0,10 @@ | ||
import { Cancellation } from './Cancellation.js'; | ||
import { noop } from './Internal.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CancellablePromise = exports.isPromiseWithCancel = void 0; | ||
const Cancellation_1 = require("./Cancellation"); | ||
const Internal_1 = require("./Internal"); | ||
/** | ||
* Determines if an arbitrary value is a thenable with a cancel method. | ||
*/ | ||
export function isPromiseWithCancel(value) { | ||
function isPromiseWithCancel(value) { | ||
return (typeof value === 'object' && | ||
@@ -11,2 +14,3 @@ typeof value.then === 'function' && | ||
} | ||
exports.isPromiseWithCancel = isPromiseWithCancel; | ||
/** | ||
@@ -18,3 +22,3 @@ * A promise with a `cancel` method. | ||
*/ | ||
export class CancellablePromise { | ||
class CancellablePromise { | ||
/** | ||
@@ -94,3 +98,3 @@ * @param promise a normal promise or thenable | ||
static resolve(value) { | ||
return new CancellablePromise(Promise.resolve(value), noop); | ||
return new CancellablePromise(Promise.resolve(value), Internal_1.noop); | ||
} | ||
@@ -106,3 +110,3 @@ /** | ||
static reject(reason) { | ||
return new CancellablePromise(Promise.reject(reason), noop); | ||
return new CancellablePromise(Promise.reject(reason), Internal_1.noop); | ||
} | ||
@@ -160,3 +164,3 @@ static all(promises) { | ||
let timer; | ||
let rejectFn = noop; | ||
let rejectFn = Internal_1.noop; | ||
const promise = new Promise((resolve, reject) => { | ||
@@ -169,5 +173,6 @@ timer = setTimeout(resolve, ms); | ||
clearTimeout(timer); | ||
rejectFn(new Cancellation()); | ||
rejectFn(new Cancellation_1.Cancellation()); | ||
}); | ||
} | ||
} | ||
exports.CancellablePromise = CancellablePromise; |
@@ -0,5 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Cancellation = void 0; | ||
/** | ||
* If canceled, a [[`CancellablePromise`]] should throw an `Cancellation` object. | ||
*/ | ||
export class Cancellation extends Error { | ||
class Cancellation extends Error { | ||
constructor(message = 'Promise canceled.') { | ||
@@ -9,1 +12,2 @@ super(message); | ||
} | ||
exports.Cancellation = Cancellation; |
@@ -1,3 +0,3 @@ | ||
export * from './Cancellation.js'; | ||
export * from './CancellablePromise.js'; | ||
export * from './Utils.js'; | ||
export * from './Cancellation'; | ||
export * from './CancellablePromise'; | ||
export * from './Utils'; |
@@ -1,3 +0,15 @@ | ||
export * from './Cancellation.js'; | ||
export * from './CancellablePromise.js'; | ||
export * from './Utils.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./Cancellation"), exports); | ||
__exportStar(require("./CancellablePromise"), exports); | ||
__exportStar(require("./Utils"), exports); |
@@ -0,2 +1,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.noop = void 0; | ||
/** @internal */ | ||
export const noop = () => { }; | ||
const noop = () => { }; | ||
exports.noop = noop; |
@@ -1,2 +0,2 @@ | ||
import { CancellablePromise } from './CancellablePromise.js'; | ||
import { CancellablePromise } from './CancellablePromise'; | ||
/** | ||
@@ -3,0 +3,0 @@ * Takes in a regular `Promise` and returns a `CancellablePromise`. If canceled, |
@@ -1,4 +0,7 @@ | ||
import { CancellablePromise } from './CancellablePromise.js'; | ||
import { Cancellation } from './Cancellation.js'; | ||
import { noop } from './Internal.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildCancellablePromise = exports.pseudoCancellable = void 0; | ||
const CancellablePromise_1 = require("./CancellablePromise"); | ||
const Cancellation_1 = require("./Cancellation"); | ||
const Internal_1 = require("./Internal"); | ||
/** | ||
@@ -12,5 +15,5 @@ * Takes in a regular `Promise` and returns a `CancellablePromise`. If canceled, | ||
*/ | ||
export function pseudoCancellable(promise) { | ||
function pseudoCancellable(promise) { | ||
let canceled = false; | ||
let rejectFn = noop; | ||
let rejectFn = Internal_1.noop; | ||
const newPromise = new Promise((resolve, reject) => { | ||
@@ -22,3 +25,3 @@ rejectFn = reject; | ||
resolve(result); | ||
rejectFn = noop; | ||
rejectFn = Internal_1.noop; | ||
} | ||
@@ -33,6 +36,7 @@ return undefined; | ||
canceled = true; | ||
rejectFn(new Cancellation()); | ||
rejectFn(new Cancellation_1.Cancellation()); | ||
} | ||
return new CancellablePromise(newPromise, cancel); | ||
return new CancellablePromise_1.CancellablePromise(newPromise, cancel); | ||
} | ||
exports.pseudoCancellable = pseudoCancellable; | ||
/** | ||
@@ -62,3 +66,3 @@ * Used to build a single [[`CancellablePromise`]] from a multi-step asynchronous | ||
*/ | ||
export function buildCancellablePromise(innerFunc) { | ||
function buildCancellablePromise(innerFunc) { | ||
const capturedPromises = []; | ||
@@ -72,3 +76,4 @@ const capture = (promise) => { | ||
} | ||
return new CancellablePromise(innerFunc(capture), cancel); | ||
return new CancellablePromise_1.CancellablePromise(innerFunc(capture), cancel); | ||
} | ||
exports.buildCancellablePromise = buildCancellablePromise; |
{ | ||
"name": "real-cancellable-promise", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "A simple cancellable promise implementation that cancels the underlying HTTP call.", | ||
@@ -18,3 +18,2 @@ "keywords": [ | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
@@ -21,0 +20,0 @@ "scripts": { |
@@ -1,3 +0,3 @@ | ||
import { CancellablePromise } from '../../CancellablePromise.js' | ||
import { Cancellation } from '../../Cancellation.js' | ||
import { CancellablePromise } from '../../CancellablePromise' | ||
import { Cancellation } from '../../Cancellation' | ||
@@ -4,0 +4,0 @@ export function fail(reason: string = 'fail was called in a test.'): never { |
// Jest bug: https://github.com/facebook/jest/issues/11876 | ||
// Jest bug 2: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/55803 | ||
import { CancellablePromise } from '../CancellablePromise.js' | ||
import { Cancellation } from '../Cancellation.js' | ||
import { defaultDuration, delay, getPromise, fail } from './__helpers__/index.js' | ||
import { CancellablePromise } from '../CancellablePromise' | ||
import { Cancellation } from '../Cancellation' | ||
import { defaultDuration, delay, getPromise, fail } from './__helpers__' | ||
@@ -7,0 +7,0 @@ beforeEach(() => { |
@@ -1,5 +0,5 @@ | ||
import { CancellablePromise } from '../CancellablePromise.js' | ||
import { Cancellation } from '../Cancellation.js' | ||
import { buildCancellablePromise, pseudoCancellable } from '../Utils.js' | ||
import { defaultDuration, delay, getPromise, fail } from './__helpers__/index.js' | ||
import { CancellablePromise } from '../CancellablePromise' | ||
import { Cancellation } from '../Cancellation' | ||
import { buildCancellablePromise, pseudoCancellable } from '../Utils' | ||
import { defaultDuration, delay, getPromise, fail } from './__helpers__' | ||
@@ -6,0 +6,0 @@ beforeEach(() => { |
@@ -1,3 +0,3 @@ | ||
import { Cancellation } from './Cancellation.js' | ||
import { noop } from './Internal.js' | ||
import { Cancellation } from './Cancellation' | ||
import { noop } from './Internal' | ||
@@ -4,0 +4,0 @@ /** |
@@ -1,3 +0,3 @@ | ||
export * from './Cancellation.js' | ||
export * from './CancellablePromise.js' | ||
export * from './Utils.js' | ||
export * from './Cancellation' | ||
export * from './CancellablePromise' | ||
export * from './Utils' |
@@ -1,4 +0,4 @@ | ||
import { CancellablePromise } from './CancellablePromise.js' | ||
import { Cancellation } from './Cancellation.js' | ||
import { noop } from './Internal.js' | ||
import { CancellablePromise } from './CancellablePromise' | ||
import { Cancellation } from './Cancellation' | ||
import { noop } from './Internal' | ||
@@ -5,0 +5,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66240
1381
No