Skip to content

Instantly share code, notes, and snippets.

@irrationnelle
Last active January 17, 2020 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irrationnelle/0de22bed6a33081df1bd57ff23a1a378 to your computer and use it in GitHub Desktop.
Save irrationnelle/0de22bed6a33081df1bd57ff23a1a378 to your computer and use it in GitHub Desktop.
import { from } from "rxjs";
import { concatMap } from 'rxjs/operators';
class Test {
someArray = [1,2,3,4,5,6,7,8,9,10,11,12];
constructor() {
from(this.someArray).pipe(
concatMap(this.delayedPromise)
).subscribe(console.log)
}
delayedPromise = (n: number): Promise<number> => new Promise((resolve => {
setTimeout(() => {
resolve(n+1)
}, this.getRandomArbitrary(100, 1000))
}));
getRandomArbitrary = (min: number, max: number): number => Math.random() * (max - min) + min;
}
const test = new Test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment