rxjs#timer JavaScript Examples

The following examples show how to use rxjs#timer. 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: staking_payouts.js    From sdk with MIT License 6 votes vote down vote up
signAndSendExtrinsics = curry((dock, initiator, txs$) => {
  // The first nonce to be used will come from the API call
  // To send several extrinsics simultaneously, we need to emulate increasing nonce
  return from(dock.api.rpc.system.accountNextIndex(initiator.address)).pipe(
    switchMap((nonce) => {
      const sendExtrinsic = (tx) =>
        defer(() => {
          dock.setAccount(initiator);
          const sentTx = dock.signAndSend(tx, FinalizeTx, { nonce });
          // Increase nonce by hand
          nonce = nonce.add(new BN(1));

          return from(timeout(TxFinalizationTimeout, sentTx));
        }).pipe(
          mapRx((result) => ({ tx, result })),
          catchError((error, caught) => {
            console.error(` * Transaction failed: ${error}`);
            const stringified = error.toString().toLowerCase();

            // Filter out errors related to balance and double-claim
            if (
              stringified.includes("balance") ||
              stringified.includes("alreadyclaimed") ||
              stringified.includes("invalid transaction") ||
              stringified.includes("election")
            ) {
              return EMPTY;
            } else {
              // Retry an observable after the given timeout
              return timer(RetryTimeout).pipe(concatMapTo(caught));
            }
          })
        );

      return txs$.pipe(mergeMap(sendExtrinsic, ConcurrentTxLimit));
    })
  );
})
Example #2
Source File: OnlineAccountClient.js    From invizi with GNU General Public License v3.0 6 votes vote down vote up
// Fetch all trades, all deposits and withdraws
  // returns obs
  synchronizeTransactions (account, symbolCurrencyPair, apiKeys, params) {
    const allTrades$ = this.getMyTradesObs(...arguments)
    const withdrawals$ = this.getWithdrawalsObs(...arguments)
    const deposits$ = from(this.getDepositsObs(...arguments))
    const timer$ = timer(5000)
    const maxIter = this.allTransactionsMaxIter(account.name)
    let currentIter = 1

    let load$ = concat(deposits$, timer$, withdrawals$, timer$, allTrades$).pipe(
      tap(data => {
        console.log(data)
      }),
      filter(data => data), // filter timerObs values
      map(result => {
        let tradesFiltered = result.data
        // if (account.last_sync_at) {
        //   tradesFiltered = result.data.filter(trade => trade.date > account.last_sync_at / 1000)
        // }
        tradesFiltered.progress = (currentIter + 1) / maxIter
        currentIter++
        return result
      })
    )
    return load$
  }