Last active
December 28, 2022 19:43
-
-
Save Restuta/ee4cc5f3f7d9e6cc485798228326a9da to your computer and use it in GitHub Desktop.
run promises sequentially or not using observables
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
import * as O from 'rxjs'; | |
const delay = ms => new Promise((resolve) => setTimeout(() => resolve(ms), ms)); | |
O.from([1,2,3]) | |
.pipe( | |
O.map(x => O.defer(() => delay(1000))), | |
O.mergeAll(1) | |
).subscribe(x => console.log(x)) | |
console.log('done') | |
// allows grouiping / batching by count | |
import * as O from 'rxjs'; | |
console.log('hi') //? | |
const delay = (ms, value) => | |
new Promise((resolve) => setTimeout(() => resolve(value), ms)); | |
O.from([1,2,3, 4, 5, 6, 7, 8, 9 , 10]) | |
.pipe( | |
O.bufferCount(3), | |
O.map(x => O.defer(() => delay(1000, x))), | |
O.mergeAll(1) | |
).subscribe(x => console.log(x)) | |
console.log('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will execute promises with concurrency passed to
mergeAll