-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
6b338f1
commit 3a103c3
Showing
7 changed files
with
58 additions
and
84 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
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 |
---|---|---|
@@ -1,58 +1,40 @@ | ||
declare namespace pWaitFor { | ||
interface Options { | ||
/** | ||
Number of milliseconds to wait before retrying `condition`. | ||
export interface Options { | ||
/** | ||
Number of milliseconds to wait before retrying `condition`. | ||
@default 20 | ||
*/ | ||
readonly interval?: number; | ||
@default 20 | ||
*/ | ||
readonly interval?: number; | ||
|
||
/** | ||
Number of milliseconds to wait before automatically rejecting. | ||
/** | ||
Number of milliseconds to wait before automatically rejecting. | ||
@default Infinity | ||
*/ | ||
readonly timeout?: number; | ||
@default Infinity | ||
*/ | ||
readonly timeout?: number; | ||
|
||
/** | ||
Whether to run the check immediately rather than starting by waiting `interval` milliseconds. | ||
/** | ||
Whether to run the check immediately rather than starting by waiting `interval` milliseconds. | ||
Useful for when the check, if run immediately, would likely return `false`. In this scenario, set `before` to `false`. | ||
Useful for when the check, if run immediately, would likely return `false`. In this scenario, set `before` to `false`. | ||
@default true | ||
*/ | ||
readonly before?: boolean; | ||
} | ||
@default true | ||
*/ | ||
readonly before?: boolean; | ||
} | ||
|
||
declare const pWaitFor: { | ||
/** | ||
Wait for a condition to be true. | ||
/** | ||
Wait for a condition to be true. | ||
@returns A promise that resolves when `condition` returns `true`. Rejects if `condition` throws or returns a `Promise` that rejects. | ||
@returns A promise that resolves when `condition` returns `true`. Rejects if `condition` throws or returns a `Promise` that rejects. | ||
@example | ||
``` | ||
import pWaitFor = require('p-wait-for'); | ||
import pathExists = require('path-exists'); | ||
@example | ||
``` | ||
import pWaitFor from 'p-wait-for'; | ||
import pathExists from 'path-exists'; | ||
(async () => { | ||
await pWaitFor(() => pathExists('unicorn.png')); | ||
console.log('Yay! The file now exists.'); | ||
})(); | ||
``` | ||
*/ | ||
(condition: () => PromiseLike<boolean> | boolean, options?: pWaitFor.Options): Promise< | ||
void | ||
>; | ||
|
||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pWaitFor( | ||
// condition: () => PromiseLike<boolean> | boolean, | ||
// options?: pWaitFor.Options | ||
// ): Promise<void>; | ||
// export = pWaitFor; | ||
default: typeof pWaitFor; | ||
}; | ||
|
||
export = pWaitFor; | ||
await pWaitFor(() => pathExists('unicorn.png')); | ||
console.log('Yay! The file now exists.'); | ||
``` | ||
*/ | ||
export default function pWaitFor(condition: () => PromiseLike<boolean> | boolean, options?: Options): Promise<void>; |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {expectType} from 'tsd'; | ||
import pWaitFor = require('.'); | ||
import pWaitFor from './index.js'; | ||
|
||
expectType<Promise<void>>(pWaitFor(() => false)); | ||
expectType<Promise<void>>(pWaitFor(() => Promise.resolve(false))); | ||
expectType<Promise<void>>(pWaitFor(async () => false)); | ||
expectType<Promise<void>>(pWaitFor(() => true, {interval: 1})); | ||
expectType<Promise<void>>(pWaitFor(() => true, {timeout: 1})); | ||
expectType<Promise<void>>(pWaitFor(() => true, {before: false})); |
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
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