Skip to content

Instantly share code, notes, and snippets.

@rafagsiqueira
Last active January 16, 2021 03:52
Show Gist options
  • Save rafagsiqueira/2900b16fe1c119d0c4f6bcb76bb8fc26 to your computer and use it in GitHub Desktop.
Save rafagsiqueira/2900b16fe1c119d0c4f6bcb76bb8fc26 to your computer and use it in GitHub Desktop.
Using mergeMap for parallel asynchronous calls
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