delay
Advanced tools
Comparing version 4.1.0 to 4.2.0
120
index.d.ts
@@ -1,64 +0,86 @@ | ||
export interface ClearablePromise<T> extends Promise<T> { | ||
declare namespace delay { | ||
interface ClearablePromise<T> extends Promise<T> { | ||
/** | ||
Clears the delay and settles the promise. | ||
*/ | ||
clear(): void; | ||
} | ||
/** | ||
* Clears the delay and settles the promise. | ||
*/ | ||
clear(): void; | ||
} | ||
Minimal subset of `AbortSignal` that delay will use if passed. | ||
This avoids a dependency on dom.d.ts. | ||
The dom.d.ts `AbortSignal` is compatible with this one. | ||
*/ | ||
interface AbortSignal { | ||
readonly aborted: boolean; | ||
addEventListener( | ||
type: 'abort', | ||
listener: () => void, | ||
options?: {once?: boolean} | ||
): void; | ||
removeEventListener(type: 'abort', listener: () => void): void; | ||
} | ||
/** | ||
* Minimal subset of `AbortSignal` that delay will use if passed. | ||
* This avoids a dependency on dom.d.ts. | ||
* The dom.d.ts `AbortSignal` is compatible with this one. | ||
*/ | ||
interface AbortSignal { | ||
readonly aborted: boolean; | ||
addEventListener(type: 'abort', listener: () => void, options?: { once?: boolean }): void; | ||
removeEventListener(type: 'abort', listener: () => void): void; | ||
interface Options { | ||
/** | ||
An optional AbortSignal to abort the delay. | ||
If aborted, the Promise will be rejected with an AbortError. | ||
*/ | ||
signal?: AbortSignal; | ||
} | ||
} | ||
export interface Options { | ||
type Delay = { | ||
/** | ||
* An optional AbortSignal to abort the delay. | ||
* If aborted, the Promise will be rejected with an AbortError. | ||
*/ | ||
signal?: AbortSignal | ||
} | ||
Create a promise which resolves after the specified `milliseconds`. | ||
type Delay = { | ||
@param milliseconds - Milliseconds to delay the promise. | ||
@returns A promise which resolves after the specified `milliseconds`. | ||
*/ | ||
(milliseconds: number, options?: delay.Options): delay.ClearablePromise<void>; | ||
/** | ||
* Create a promise which resolves after the specified `milliseconds`. | ||
* | ||
* @param milliseconds - Milliseconds to delay the promise. | ||
* @returns A promise which resolves after the specified `milliseconds`. | ||
*/ | ||
(milliseconds: number, options?: Options): ClearablePromise<void>; | ||
Create a promise which resolves after the specified `milliseconds`. | ||
@param milliseconds - Milliseconds to delay the promise. | ||
@returns A promise which resolves after the specified `milliseconds`. | ||
*/ | ||
<T>( | ||
milliseconds: number, | ||
options?: delay.Options & { | ||
/** | ||
Value to resolve in the returned promise. | ||
*/ | ||
value: T; | ||
} | ||
): delay.ClearablePromise<T>; | ||
/** | ||
* Create a promise which resolves after the specified `milliseconds`. | ||
* | ||
* @param milliseconds - Milliseconds to delay the promise. | ||
* @returns A promise which resolves after the specified `milliseconds`. | ||
*/ | ||
<T>(milliseconds: number, options?: Options & { | ||
/** Value to resolve in the returned promise. */ | ||
value: T | ||
}): ClearablePromise<T>; | ||
Create a promise which rejects after the specified `milliseconds`. | ||
/** | ||
* Create a promise which rejects after the specified `milliseconds`. | ||
* | ||
* @param milliseconds - Milliseconds to delay the promise. | ||
* @returns A promise which rejects after the specified `milliseconds`. | ||
*/ | ||
@param milliseconds - Milliseconds to delay the promise. | ||
@returns A promise which rejects after the specified `milliseconds`. | ||
*/ | ||
// TODO: Allow providing value type after https://github.com/Microsoft/TypeScript/issues/5413 will be resolved. | ||
reject(milliseconds: number, options?: Options & { | ||
/** Value to reject in the returned promise. */ | ||
value?: any | ||
}): ClearablePromise<never>; | ||
} | ||
reject( | ||
milliseconds: number, | ||
options?: delay.Options & { | ||
/** | ||
Value to reject in the returned promise. | ||
*/ | ||
value?: unknown; | ||
} | ||
): delay.ClearablePromise<never>; | ||
}; | ||
declare const delay: Delay & { | ||
createWithTimers(timers: {clearTimeout: typeof clearTimeout, setTimeout: typeof setTimeout}): Delay | ||
createWithTimers(timers: { | ||
clearTimeout: typeof clearTimeout; | ||
setTimeout: typeof setTimeout; | ||
}): Delay; | ||
// TODO: Remove this for the next major release | ||
default: typeof delay; | ||
}; | ||
export default delay; | ||
export = delay; |
@@ -38,2 +38,3 @@ 'use strict'; | ||
}; | ||
rejectFn = reject; | ||
@@ -64,3 +65,5 @@ timeoutId = set(settle, ms); | ||
}; | ||
module.exports = delay; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = delay; |
{ | ||
"name": "delay", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Delay a promise a specified amount of time", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -43,10 +43,10 @@ "files": [ | ||
"devDependencies": { | ||
"abort-controller": "^1.0.2", | ||
"ava": "1.0.0-beta.8", | ||
"abort-controller": "^3.0.0", | ||
"ava": "1.4.1", | ||
"currently-unhandled": "^0.4.1", | ||
"in-range": "^1.0.0", | ||
"time-span": "^2.0.0", | ||
"tsd-check": "^0.2.1", | ||
"xo": "*" | ||
"time-span": "^3.0.0", | ||
"tsd": "^0.7.1", | ||
"xo": "^0.24.0" | ||
} | ||
} |
9247
130