Last active
February 18, 2019 21:13
-
-
Save kosich/f0c8048d10c0fe42f1e52220ba73eae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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