Skip to content

Commit

Permalink
Rename leadingCheck option to before (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richienb committed Apr 6, 2021
1 parent df45dd3 commit 6b338f1
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ declare namespace pWaitFor {
/**
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 `leadingCheck` to `false`.
Useful for when the check, if run immediately, would likely return `false`. In this scenario, set `before` to `false`.
@default true
*/
readonly leadingCheck?: boolean;
readonly before?: boolean;
}
}

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pWaitFor = async (condition, options) => {
options = {
interval: 20,
timeout: Infinity,
leadingCheck: true,
before: true,
...options
};

Expand All @@ -30,7 +30,7 @@ const pWaitFor = async (condition, options) => {
}
};

if (options.leadingCheck) {
if (options.before) {
check();
} else {
retryTimeout = setTimeout(check, options.interval);
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ expectType<Promise<void>>(pWaitFor(() => false));
expectType<Promise<void>>(pWaitFor(() => Promise.resolve(false)));
expectType<Promise<void>>(pWaitFor(() => true, {interval: 1}));
expectType<Promise<void>>(pWaitFor(() => true, {timeout: 1}));
expectType<Promise<void>>(pWaitFor(() => true, {leadingCheck: false}));
expectType<Promise<void>>(pWaitFor(() => true, {before: false}));
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ Default: `Infinity`

Number of milliseconds to wait before automatically rejecting.

##### leadingCheck
##### before

Type: `boolean`\
Default: `true`

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 `leadingCheck` to `false`.
Useful for when the check, if run immediately, would likely return `false`. In this scenario, set `before` to `false`.

## Related

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('does not perform a leading check', async t => {

await pWaitFor(async () => true, {
interval: ms,
leadingCheck: false
before: false
});

t.true(end() > (ms - 20));
Expand Down

0 comments on commit 6b338f1

Please sign in to comment.