-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1550 from input-output-hk/fix/fatal-provider-errors
fix: fatal provider errors
- Loading branch information
Showing
27 changed files
with
394 additions
and
516 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 |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
{ | ||
"path": "../../util/src" | ||
}, | ||
{ | ||
"path": "../../util-rxjs/src" | ||
}, | ||
{ | ||
"path": "../../core/src" | ||
}, | ||
|
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Logger } from 'ts-log'; | ||
import { | ||
NEVER, | ||
Observable, | ||
concat, | ||
defer, | ||
distinctUntilChanged, | ||
from, | ||
mergeMap, | ||
of, | ||
switchMap, | ||
takeUntil, | ||
throwError | ||
} from 'rxjs'; | ||
import { RetryBackoffConfig, retryBackoff } from 'backoff-rxjs'; | ||
import { strictEquals } from '@cardano-sdk/util'; | ||
|
||
const POLL_UNTIL_RETRY = Symbol('POLL_UNTIL_RETRY'); | ||
|
||
export interface PollProps<T> { | ||
sample: () => Promise<T>; | ||
retryBackoffConfig: RetryBackoffConfig; | ||
trigger$?: Observable<unknown>; | ||
equals?: (t1: T, t2: T) => boolean; | ||
combinator?: typeof switchMap; | ||
cancel$?: Observable<unknown>; | ||
pollUntil?: (v: T) => boolean; | ||
logger: Logger; | ||
} | ||
|
||
export const poll = <T>({ | ||
sample, | ||
retryBackoffConfig, | ||
trigger$ = of(true), | ||
equals = strictEquals, | ||
combinator = switchMap, | ||
cancel$ = NEVER, | ||
pollUntil = () => true, | ||
logger | ||
}: PollProps<T>) => | ||
trigger$.pipe( | ||
combinator(() => | ||
defer(() => | ||
from(sample()).pipe( | ||
mergeMap((v) => | ||
pollUntil(v) | ||
? of(v) | ||
: // Emit value, but also throw error to force retryBackoff to kick in | ||
concat( | ||
of(v), | ||
throwError(() => POLL_UNTIL_RETRY) | ||
) | ||
) | ||
) | ||
).pipe( | ||
retryBackoff({ | ||
...retryBackoffConfig, | ||
shouldRetry: (error) => { | ||
if (error === POLL_UNTIL_RETRY) { | ||
logger.warn('"pollUntil" condition not met, will retry'); | ||
return true; | ||
} | ||
|
||
logger.error(error); | ||
|
||
if (retryBackoffConfig.shouldRetry) { | ||
const shouldRetry = retryBackoffConfig.shouldRetry(error); | ||
logger.debug(`Should retry: ${shouldRetry}`); | ||
return shouldRetry; | ||
} | ||
|
||
return true; | ||
} | ||
}) | ||
) | ||
), | ||
distinctUntilChanged(equals), | ||
takeUntil(cancel$) | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.