Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 22, 2018 14:44
Show Gist options
  • Save ajcrites/c005359dab9a6a63510587e30adf781c to your computer and use it in GitHub Desktop.
Save ajcrites/c005359dab9a6a63510587e30adf781c to your computer and use it in GitHub Desktop.
import { of } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
of(1).pipe(
map(async () => await Promise.resolve('hello?')),
// mergeMap incuded here because of how it's written in the original code.
// It has no effect on the async value that's passed in.
mergeMap(customerId => {
// Promise { <pending> }
console.log(customerId);
return [];
}),
).subscribe();
of(1).pipe(
map(() => Promise.resolve('hello?')),
mergeMap(customerId => {
// Promise { 'hello?' }
console.log(customerId);
return [];
}),
).subscribe();
// 'hello!'
of(1).pipe(mergeMap(() => Promise.resolve('hello!'))).subscribe(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment