Skip to content

Instantly share code, notes, and snippets.

@obaranovskyi
Created December 10, 2021 15:22
Show Gist options
  • Save obaranovskyi/0e16e701fa22cecce89853d8dccb9925 to your computer and use it in GitHub Desktop.
Save obaranovskyi/0e16e701fa22cecce89853d8dccb9925 to your computer and use it in GitHub Desktop.
import {
combineLatest,
of,
merge,
concat,
exhaustMap,
mergeMap,
concatMap,
forkJoin,
} from 'rxjs';
import { switchMap, withLatestFrom } from 'rxjs/operators';
combineLatest([Promise.resolve(2), Promise.resolve(3)]).subscribe((value) =>
console.log(`combineLatest: ${value}`)
);
forkJoin({ obs1: Promise.resolve(1), obs2: Promise.resolve(2) }).subscribe(
(value) => console.log(`forkJoin: ${JSON.stringify(value)}`)
);
of(1)
.pipe(withLatestFrom(Promise.resolve(3)))
.subscribe((value) => console.log(`withLatestFrom: ${value}`));
of(1)
.pipe(switchMap((value) => of(5)))
.subscribe((value) => console.log(`switchMap: ${value}`)); // 5
of(1)
.pipe(exhaustMap((value) => of(5)))
.subscribe((value) => console.log(`exhaustMap: ${value}`)); // 5
of(1)
.pipe(mergeMap((value) => of(5)))
.subscribe((value) => console.log(`mergeMap: ${value}`)); // 5
of(1)
.pipe(concatMap((value) => of(5)))
.subscribe((value) => console.log(`concatMap: ${value}`)); // 5
merge(Promise.resolve(1), Promise.resolve(2)).subscribe((value) =>
console.log(`merge: ${value}`)
);
concat(Promise.resolve(1), Promise.resolve(2)).subscribe((value) =>
console.log(`concat: ${value}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment