Skip to content

Instantly share code, notes, and snippets.

@EnricoPicci
Last active February 21, 2022 22:57
Show Gist options
  • Save EnricoPicci/a5b225bb645b072e6e87debb9304cfa9 to your computer and use it in GitHub Desktop.
Save EnricoPicci/a5b225bb645b072e6e87debb9304cfa9 to your computer and use it in GitHub Desktop.
// example of how to use bufferConcatMap
import { delay, interval, of, take } from 'rxjs';
import { bufferConcatMap } from './bufferedConcatMap';
// source Observable
const source = interval(100).pipe(take(5));
// new transformed Observable created with bufferConcatMap
// this is when bufferConcatMap is actually invoked
const newTransformedObs = source.pipe(bufferConcatMap((n) => of(n).pipe(delay(1000))));
// subscribe the new Observable
// it is only at subscription time, i.e. here, that the Pipeable Operator,
// i.e. the function returned by bufferConcatMap, is actually invoked
newTransformedObs.subscribe(console.log);
// prints: [0], [1,2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment