All files / rxmq.js/src/rx endlessSubject.js

100% Statements 3/3
100% Branches 0/0
100% Functions 2/2
100% Lines 3/3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                  3x   3x   3x            
/* eslint no-param-reassign: [2, {"props": false}] */
import { Subject } from 'rxjs';
 
/**
 * EndlessSubject extension of Rx.Subject.
 * This is pretty hacky, but so far I'd found no better way of having
 * Subjects that do no close on multicasted stream completion and on multiple errors.
 * For documentation refer to
 * [Rx.Subject docs](@link https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/subject.md).
 * The only difference is that EndlessSubject never triggers '.complete()' and
 * does not closes observers on errors (thus allowing to continuously dispatch them).
 */
class EndlessSubject extends Subject {
  /**
   * Dummy method override to prevent execution and Rx.Observable completion
   * @return {void}
   */
  complete() {}
 
  /**
   * Override of error method that prevents stopping that Rx.Observer
   * @param  {Error} error  - Error to be dispatched
   * @return {void}
   */
  error(error) {
    this.thrownError = error;
    // dispatch to all observers
    this.observers.forEach(os => {
      // dispatch directly to destination
      os.destination._error.call(os.destination._context, error);
    });
  }
}
 
export { EndlessSubject };