-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e202e5
commit 3e383c6
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
interface ClearablePromise<T> extends Promise<T> { | ||
/** | ||
* Clears the delay and settles the promise. | ||
*/ | ||
clear(): void; | ||
} | ||
|
||
declare const delay: { | ||
/** | ||
* 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): ClearablePromise<void>; | ||
|
||
/** | ||
* Create a promise which resolves after the specified `milliseconds`. | ||
* | ||
* @param milliseconds - Milliseconds to delay the promise. | ||
* @param value - Value to resolve in the returned promise. | ||
* @returns A promise which resolves after the specified `milliseconds`. | ||
*/ | ||
<T>(milliseconds: number, value: T): ClearablePromise<T>; | ||
|
||
/** | ||
* Create a promise which rejects after the specified `milliseconds`. | ||
* | ||
* @param milliseconds - Milliseconds to delay the promise. | ||
* @param reason - Value to reject in the returned promise. | ||
* @returns A promise which rejects after the specified `milliseconds`. | ||
*/ | ||
// TODO: Allow providing reason type after https://github.com/Microsoft/TypeScript/issues/5413 will be resolved. | ||
reject(milliseconds: number, reason?: any): ClearablePromise<never>; | ||
}; | ||
|
||
export default delay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ | |
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"promise", | ||
|