Last active
July 11, 2020 15:58
-
-
Save NyaGarcia/1aed6a260b61b3fa2f2b3b285a64a102 to your computer and use it in GitHub Desktop.
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
const pokemonId$ = of(1, 5, 6); | |
function getPokemonName(id: number) { | |
return ajax.getJSON(`https://pokeapi.co/api/v2/pokemon/${id}`).pipe( | |
map(({ name }) => name), | |
delay(2000) | |
); | |
} | |
// concatAll subscribes to each inner Observable only after the previous one has completed: it will wait until each request is done, before making a new one | |
pokemonId$ | |
.pipe( | |
map(id => getPokemonName(id)), | |
concatAll() | |
) | |
.subscribe(console.log); | |
// Output: (2s) bulbasaur, (2s) charmeleon, (2s) charizard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment