multicast

signature: multicast(selector: Function): Observable

Example 1: multicast with standard Subject
Example 2: multicast with ReplaySubject
  1. import { interval } from 'rxjs/observable/of';
  2. import { take, multicast } 'rxjs/operators';
  3. const source = interval(2000).pipe(take(5));
  4. const example = source.pipe(
  5. //since we are multicasting below, side effects will be executed once
  6. tap(_ => console.log('Side Effect #2')),
  7. mapTo('Result Two!')
  8. );
  9. //can use any type of subject
  10. multi.connect();
  11. setTimeout(() => {
  12. /*
  13. subscriber will receieve all previous values on subscription because
  14. of ReplaySubject
  15. */

Additional Resources