rxjs/operators#takeWhile JavaScript Examples

The following examples show how to use rxjs/operators#takeWhile. 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: KrakenExchangeClient.js    From invizi with GNU General Public License v3.0 6 votes vote down vote up
// fetch deposits AND withdrawal
  getDepositsObs (apiKey, symbolCurrencyPair = undefined, params = {}) {
    let counter = -1
    this.initializeApiKey(apiKey)
    const query = () => {
      counter++
      return this.ccxt.fetchLedger(undefined, undefined, undefined, {ofs: counter * 50})
    }

    const trades$ = defer(query)

    let load$ = new BehaviorSubject('')

    const whenToRefresh$ = of('').pipe(
      delay(5000),
      tap(_ => load$.next('')),
      skip(1))

    const byDepositAndWithdrawal = trade => trade && ['deposit', 'withdrawal'].includes(trade.info.type)

    const poll$ = concat(trades$, whenToRefresh$)

    return load$.pipe(
      concatMap(_ => poll$),
      takeWhile(data => data.length > 0),
      map(data => ({errors: [], data: data.filter(byDepositAndWithdrawal).map(parseLedger)})),
      catchError(error$ => of({errors: [error$.toString()], data: []})))
  }
Example #2
Source File: KrakenExchangeClient.js    From invizi with GNU General Public License v3.0 6 votes vote down vote up
getMyTradesObs (apiKey, symbolCurrencyPair = undefined, params = {}) {
    let counter = -1
    this.initializeApiKey(apiKey)
    const fetchTrades = () => {
      counter++
      return super.getMyTrades(apiKey, undefined, {ofs: counter * 50})
    }

    const trades$ = defer(() => fetchTrades())

    let load$ = new BehaviorSubject('')

    const whenToRefresh$ = of('').pipe(
      delay(5000),
      tap(_ => load$.next('')),
      skip(1))

    const poll$ = concat(trades$, whenToRefresh$)
    let result$ = load$.pipe(
      concatMap(_ => poll$),
      takeWhile(data => data.length > 0),
      map(data => ({errors: [], data})),
      catchError(error$ => {
        return of({errors: [error$.toString()], data: []})
      }))
    return result$
  }