rxjs#retry TypeScript Examples

The following examples show how to use rxjs#retry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auth.ts    From bext with MIT License 6 votes vote down vote up
octokit$
  .pipe(
    switchMap((octokit) =>
      octokit
        ? from(octokit.rest.users.getAuthenticated()).pipe(
            map(({ data, status }) =>
              status === 200
                ? ({ status: 'complete', user: data } as const)
                : ({ status: 'error' } as const),
            ),
            startWith({ status: 'loading' } as const),
            retry(2),
            catchError(() => of({ status: 'error' } as const)),
          )
        : of({ status: 'unauth' } as const),
    ),
  )
  .subscribe(user$);
Example #2
Source File: publish-list.tsx    From bext with MIT License 5 votes vote down vote up
PublishList: FC = () => (
  <div className="py-3">
    {useObservableState(
      useObservable(() =>
        user$.pipe(
          switchMap(({ status, user }) => {
            switch (status) {
              case 'loading':
                return of(<Spinner />);
              case 'complete':
                const octokit = octokit$.getValue()!;
                return timer(0, REFRESH_DURATION).pipe(
                  switchMap(() =>
                    from(
                      octokit.paginate(octokit.search.issuesAndPullRequests, {
                        q: `is:pr author:${user?.login} repo:${packageJson.metaRepository.owner}/${packageJson.metaRepository.repo}`,
                        sort: 'created',
                        order: 'desc',
                      }),
                    ).pipe(
                      map((items) => (
                        <>
                          <Banner current={Date.now()} empty={!items.length} />
                          {items.length ? (
                            <List
                              items={items}
                              onRenderCell={(item) => <PrItem item={item!} />}
                            />
                          ) : null}
                        </>
                      )),
                      retry(2),
                      catchError(() =>
                        of(<div className="text-center">出错了...</div>),
                      ),
                    ),
                  ),
                );
              default:
                return of(
                  <div className="text-center">
                    <LoginLink /> 后查看发布历史
                  </div>,
                );
            }
          }),
          startWith(<Spinner />),
        ),
      ),
    ) || null}
  </div>
)
Example #3
Source File: wrapped-control-superclass.ts    From s-libs with MIT License 5 votes vote down vote up
#handleError<T>(): MonoTypeOperatorFunction<T> {
    return flow(
      tap<T>({ error: bindKey(this.#errorHandler, 'handleError') }),
      retry(),
    );
  }