Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

exhaust.js 1.0KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { SimpleOuterSubscriber, innerSubscribe, SimpleInnerSubscriber } from '../innerSubscribe';
  2. export function exhaust() {
  3. return (source) => source.lift(new SwitchFirstOperator());
  4. }
  5. class SwitchFirstOperator {
  6. call(subscriber, source) {
  7. return source.subscribe(new SwitchFirstSubscriber(subscriber));
  8. }
  9. }
  10. class SwitchFirstSubscriber extends SimpleOuterSubscriber {
  11. constructor(destination) {
  12. super(destination);
  13. this.hasCompleted = false;
  14. this.hasSubscription = false;
  15. }
  16. _next(value) {
  17. if (!this.hasSubscription) {
  18. this.hasSubscription = true;
  19. this.add(innerSubscribe(value, new SimpleInnerSubscriber(this)));
  20. }
  21. }
  22. _complete() {
  23. this.hasCompleted = true;
  24. if (!this.hasSubscription) {
  25. this.destination.complete();
  26. }
  27. }
  28. notifyComplete() {
  29. this.hasSubscription = false;
  30. if (this.hasCompleted) {
  31. this.destination.complete();
  32. }
  33. }
  34. }
  35. //# sourceMappingURL=exhaust.js.map