rxjs/operators#repeatWhen TypeScript Examples

The following examples show how to use rxjs/operators#repeatWhen. 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: token.service.ts    From gnosis.1inch.exchange with MIT License 6 votes vote down vote up
public getSortedTokens(walletAddress: string): Observable<ITokenDescriptor[]> {

    if (!this.tokenData$) {
      const tokenData$ = this.tokens$.pipe(
        mergeMap((symbols2Tokens: ISymbol2Token) => {

          return this.tokenDataHelperService.getTokenBalancesAndPrices(
            walletAddress,
            symbols2Tokens
          );
        }),
      );

      this.tokenData$ = tokenData$.pipe(
        shareReplay({ bufferSize: 1, refCount: true })
      );

      const update$ = combineLatest([this.tokenHelper$, this.tokens$, tokenData$]).pipe(
        tap(([tokenHelper, symbols2Tokens, tokenData]) => {
          this.assignPricesAndBalances2Tokens(tokenHelper, symbols2Tokens, tokenData);
        }),
        repeatWhen((completed) => completed.pipe(delay(20000)))
      );

      this.subscription.add(update$.subscribe());
    }

    return combineLatest([this.tokenHelper$, this.tokens$, this.tokenData$]).pipe(
      map(([tokenHelper, symbols2Tokens, tokenData]) => {
        return this.sortTokens(tokenHelper, tokenData, symbols2Tokens);
      })
    );
  }
Example #2
Source File: artichoke.ts    From closer-sdk.js with MIT License 6 votes vote down vote up
constructor(
    private artichokeApi: ArtichokeApi,
    private callFactory: CallFactory,
    private roomFactory: RoomFactory,
    private loggerService: LoggerService,
    private heartbeatTimeoutMultiplier: number,
    private fallbackReconnectDelayMs: number,
  ) {
    // Do not move this as a property accessor, it must be only one object to make rx `share` operator work.
    this.connection = merge(
      this.artichokeApi.connection$.pipe(
        filter(serverEvents.OutputHeartbeat.is),
        tap((ev: serverEvents.OutputHeartbeat) => this.handleHeartbeatEvent(ev)),
        ignoreElements(),
      ),
      this.artichokeApi.connection$.pipe(
        filter(serverEvents.Hello.is),
        tap(ev => this.handleHelloEvent(ev)),
      ),
    ).pipe(
      finalize(() => this.handleDisconnect()),
      // On WebSocket error
      retryWhen(errors => this.delayReconnect(errors)),
      takeUntil(this.serverUnreachableEvent),
      // On WebSocket gracefull close
      repeatWhen(attempts => this.delayReconnect(attempts)),
      // IMPORTANT
      // Share the observable, so the internal logic would behave like one consistent stream
      // Without this operator, if client subscribes two times, we would have
      // two heartbeats answers and reconnections logic
      share(),
    );
  }
Example #3
Source File: dia-backend-asset-repository.service.ts    From capture-lite with GNU General Public License v3.0 6 votes vote down vote up
readonly postCaptures$ = merge(
    this.postCapturesCache$,
    this.postCapturesCount$.pipe(
      first(),
      concatMap(count =>
        this.list$({
          orderBy: 'source_transaction',
          limit: count,
        })
      ),
      tap(response => this.postCapturesCache$.next(response)),
      repeatWhen(() => this.postCapturesUpdated$)
    )
  ).pipe(distinctUntilChanged());
Example #4
Source File: dia-backend-auth.service.ts    From capture-lite with GNU General Public License v3.0 6 votes vote down vote up
readonly avatar$ = defer(() => this.getAuthHeaders()).pipe(
    concatMap(headers =>
      this.httpClient.get<GetAvatarResponse>(
        `${BASE_URL}/auth/users/profile/`,
        { headers }
      )
    ),
    pluck('profile_picture_thumbnail'),
    isNonNullable(),
    repeatWhen(() => this.refreshAvatar$)
  );
Example #5
Source File: app.component.ts    From gnosis.1inch.exchange with MIT License 5 votes vote down vote up
constructor(
        private oneInchApiService: OneInchApiService,
        private gnosisService: GnosisService,
        private tokenPriceService: TokenPriceService,
        public tokenService: TokenService,
        private ethereumService: EthereumService,
        iconRegistry: MatIconRegistry,
        sanitizer: DomSanitizer
    ) {

        iconRegistry.addSvgIcon('settings', sanitizer.bypassSecurityTrustResourceUrl('assets/settings.svg'));
        iconRegistry.addSvgIcon('swap', sanitizer.bypassSecurityTrustResourceUrl('assets/swap.svg'));

        // need to subscribe before addListener
        this.gnosisService.walletAddress$.subscribe();
        // this.gnosisService.isMainNet$.subscribe(console.log);

        this.sortedTokens$ = this.gnosisService.walletAddress$.pipe(
            switchMap((walletAddress) => {
                return combineLatest([
                    this.tokenService.getSortedTokens(walletAddress),
                    this.tokenService.tokenHelper$
                ]);
            }),
            map(([tokens, tokenHelper]) => {

                this.updateFromAmountValidator(tokenHelper);
                this.openLoader = false;
                return tokens;
            }),
            shareReplay({bufferSize: 1, refCount: true})
        );

        this.filteredFromTokens$ = this.getFilteredTokens(this.autoCompleteCtrlFromToken);
        this.filteredToTokens$ = this.getFilteredTokens(this.autoCompleteCtrlToToken);

        this.swapForm.controls.fromAmount.setValue(this.fromAmount, {emitEvent: false});

        const fromAmountChange$ = this.swapForm.controls.fromAmount.valueChanges.pipe(
            startWith(this.fromAmount),
            debounceTime(200),
            distinctUntilChanged(),
            map((value: string) => ({
                fromAmount: value,
                resetFields: true
            }))
        );

        const fromAmountListener$ = merge(fromAmountChange$, this.updateAmounts.asObservable())
            .pipe(
                switchMap((({fromAmount}) => {
                    return this.setAmounts(fromAmount).pipe(
                        // background refresh
                        repeatWhen((completed) => completed.pipe(delay(20000)))
                    );
                }))
            );

        this.subscription.add(fromAmountListener$.subscribe());
        this.gnosisService.addListeners();
    }
Example #6
Source File: dia-backend-asset-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
private readonly postCapturesCount$ = this.list$({
    limit: 1,
    orderBy: 'source_transaction',
  }).pipe(
    pluck('count'),
    repeatWhen(() => this.postCapturesUpdated$)
  );
Example #7
Source File: dia-backend-contact-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
private readonly allCount$ = this.list$({ limit: 1 }).pipe(
    pluck('count'),
    repeatWhen(() => this.contactsUpdated$)
  );
Example #8
Source File: dia-backend-contact-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
readonly all$ = this.allCount$.pipe(
    first(),
    concatMap(count => this.list$({ limit: count })),
    repeatWhen(() => this.contactsUpdated$)
  );
Example #9
Source File: dia-backend-transaction-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
private readonly allCount$ = this.list$({ limit: 1 }).pipe(
    pluck('count'),
    repeatWhen(() => this.updated$)
  );
Example #10
Source File: dia-backend-transaction-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
private readonly inboxCount$ = this.listInbox$({ limit: 1 }).pipe(
    pluck('count'),
    repeatWhen(() => this.updated$)
  );
Example #11
Source File: dia-backend-transaction-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
readonly all$ = this.allCount$.pipe(
    first(),
    concatMap(count => this.list$({ limit: count })),
    repeatWhen(() => this.updated$)
  );
Example #12
Source File: dia-backend-transaction-repository.service.ts    From capture-lite with GNU General Public License v3.0 5 votes vote down vote up
readonly inbox$ = this.inboxCount$.pipe(
    first(),
    concatMap(count => this.listInbox$({ limit: count })),
    repeatWhen(() => this.updated$)
  );