Skip to content

Commit 5b78ef9

Browse files
committed
3.0.0
1 parent d6cff64 commit 5b78ef9

16 files changed

Lines changed: 112 additions & 96 deletions

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ async function foo() {
3232

3333
// try calling function
3434
try {
35-
const val = tryCall(throwingFunc, {
35+
const val = await tryCall(throwingFunc, {
3636
interval: 100,
3737
numAttempts: 10,
38-
onAttempt: (i, success) => {
38+
onAttempt: (err, i, success) => {
39+
if (err) {
40+
console.error(err)
41+
}
3942
console.log(`attempt ${i} ${success ? 'was successful' : 'failed'}`)
4043
},
4144
})
@@ -46,13 +49,14 @@ async function foo() {
4649

4750
// repeat until
4851
try {
49-
const val = tryUntil(
52+
const val = await tryUntil(
5053
() => Math.random(),
5154
(val) => val < 0.1,
5255
{
5356
interval: 100,
5457
numAttempts: 10,
55-
onAttempt: (i, success) => {
58+
onAttempt: (result, i, success) => {
59+
console.log('received', result)
5660
console.log(`attempt ${i} ${success ? 'was successful' : 'failed'}`)
5761
},
5862
},

lib/Options.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
interface Options {
2-
interval: number;
3-
numAttempts: number;
4-
onAttempt?: (iteration: number, success: boolean) => void;
5-
}
6-
export default Options;
1+
interface Options {
2+
interval: number;
3+
numAttempts: number;
4+
}
5+
export default Options;

lib/Options.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default as tryCall } from './tryCall';
2-
export { default as tryUntil } from './tryUntil';
1+
export { default as tryCall } from './tryCall';
2+
export { default as tryUntil } from './tryUntil';

lib/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tryCall.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
import Options from './Options';
2-
declare const _default: <ReturnValueType>(func: (iteration: number) => ReturnValueType, {interval, numAttempts, onAttempt}: Options) => Promise<ReturnValueType>;
3-
export default _default;
1+
import Options from './Options';
2+
interface TryCallOptions extends Options {
3+
onAttempt?: (err: Error | null, iteration: number, success: boolean) => void;
4+
}
5+
declare const _default: <ReturnValueType>(func: (iteration: number) => ReturnValueType, { interval, numAttempts, onAttempt, }: TryCallOptions) => Promise<ReturnValueType>;
6+
export default _default;

lib/tryCall.js

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tryCall.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tryUntil.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
import Options from './Options';
2-
declare const _default: <ReturnValueType>(func: (iteration: number) => ReturnValueType, validate: (val: ReturnValueType) => boolean, {numAttempts, interval, onAttempt}: Options) => Promise<ReturnValueType>;
3-
export default _default;
1+
import Options from './Options';
2+
interface TryUntilOptions<ReturnValueType> extends Options {
3+
onAttempt?: (result: ReturnValueType, iteration: number, success: boolean) => void;
4+
}
5+
declare const _default: <ReturnValueType>(func: (iteration: number) => ReturnValueType, validate: (val: ReturnValueType) => boolean, { numAttempts, interval, onAttempt, }: TryUntilOptions<ReturnValueType>) => Promise<ReturnValueType>;
6+
export default _default;

lib/tryUntil.js

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)