Use asyncScheduler for all derives (#2043)

This commit is contained in:
Jaco Greeff
2020-03-13 12:32:42 +01:00
committed by GitHub
parent 3d0fdbd6da
commit d9dad3566a
37 changed files with 194 additions and 144 deletions
@@ -5,8 +5,8 @@
import { AccountId } from '@polkadot/types/interfaces';
import { DerivedHeartbeats } from '../types';
import { of, Observable, combineLatest } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Observable, asyncScheduler, of, combineLatest } from 'rxjs';
import { map, observeOn, switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Bytes, Option, u32 } from '@polkadot/types';
@@ -19,6 +19,7 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
return memo((): Observable<DerivedHeartbeats> =>
api.query.imOnline?.receivedHeartbeats
? api.derive.staking.overview().pipe(
observeOn(asyncScheduler),
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
combineLatest([
of(validators),
@@ -28,6 +29,7 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
validators.map((address) => [currentIndex, address]))
])
),
observeOn(asyncScheduler),
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
validators.reduce((result: DerivedHeartbeats, validator, index): DerivedHeartbeats => ({
...result,