Skip to content

Instantly share code, notes, and snippets.

@kosich
Last active February 18, 2019 21:13
Show Gist options
  • Save kosich/f0c8048d10c0fe42f1e52220ba73eae5 to your computer and use it in GitHub Desktop.
Save kosich/f0c8048d10c0fe42f1e52220ba73eae5 to your computer and use it in GitHub Desktop.
const { chart } = require('rp-api');
const { forkJoin, of } = require('rxjs');
const { delay, tap, switchMap, mapTo } = require('rxjs/operators');
mockRequest(10, 'cid').pipe(
switchMap(id =>
forkJoin(
mockSendQueue([1, 2], id),
mockRequest(10, 'sub').pipe(
switchMap(subid =>
mockSendQueue([3,4], subid)
)
)
)
)
, mapTo('done')
)
.subscribe(chart.createRxObserver());
// will emit response after time
function mockRequest (time, response) {
return of(response).pipe(
delay(time)
, tap(()=>console.log(Date.now(), response))
, tap(chart.createRxObserver())
);
}
// will emit every value in the list
// with delay equal to value
function mockSendQueue (list, suffix) {
return forkJoin(
...list
.map(value =>
mockRequest(value, suffix + ':' + value))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment