Last active
January 16, 2021 03:52
-
-
Save rafagsiqueira/2900b16fe1c119d0c4f6bcb76bb8fc26 to your computer and use it in GitHub Desktop.
Using mergeMap for parallel asynchronous calls
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 EMAIL_PARALLELISM = 5; | |
const users$ = getUsers$(); | |
users$.pipe( | |
filter(user => user.isActive), | |
mergeMap(user => sendEmail$(user.email), EMAIL_PARALLELISM) | |
).subscribe( | |
(success) => emailsSent++, | |
(err) => failedEmails++, | |
() = > console.log('Emails sent:'+emailsSent+' Emails failed:'+failedEmails) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment