Skip to content

Commit

Permalink
retryOnError refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
trosck committed Aug 11, 2022
1 parent 79ac672 commit 54bc778
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions core/retryOnError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ export default async (
tryCount: number,
onError: (error: any) => void = () => {}
) => {
let currentTry = -1
while(++currentTry < tryCount) {
let currentTry = 0
while(currentTry++ < tryCount) {
try {
const isEnd = await func()
if (isEnd) return

currentTry = -1
const result = await func()
return result
} catch(e) {
// last try
if (currentTry + 1 === tryCount) {
if (currentTry === tryCount) {
return await onError(e)
}
}
Expand Down

0 comments on commit 54bc778

Please sign in to comment.