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

AsyncSubject.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Subject } from './Subject';
  2. import { Subscription } from './Subscription';
  3. export class AsyncSubject extends Subject {
  4. constructor() {
  5. super(...arguments);
  6. this.value = null;
  7. this.hasNext = false;
  8. this.hasCompleted = false;
  9. }
  10. _subscribe(subscriber) {
  11. if (this.hasError) {
  12. subscriber.error(this.thrownError);
  13. return Subscription.EMPTY;
  14. }
  15. else if (this.hasCompleted && this.hasNext) {
  16. subscriber.next(this.value);
  17. subscriber.complete();
  18. return Subscription.EMPTY;
  19. }
  20. return super._subscribe(subscriber);
  21. }
  22. next(value) {
  23. if (!this.hasCompleted) {
  24. this.value = value;
  25. this.hasNext = true;
  26. }
  27. }
  28. error(error) {
  29. if (!this.hasCompleted) {
  30. super.error(error);
  31. }
  32. }
  33. complete() {
  34. this.hasCompleted = true;
  35. if (this.hasNext) {
  36. super.next(this.value);
  37. }
  38. super.complete();
  39. }
  40. }
  41. //# sourceMappingURL=AsyncSubject.js.map