Subject.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. // Licensed to the .NET Foundation under one or more agreements.
  3. // The .NET Foundation licenses this file to you under the MIT license.
  4. Object.defineProperty(exports, "__esModule", { value: true });
  5. exports.Subject = void 0;
  6. const Utils_1 = require("./Utils");
  7. /** Stream implementation to stream items to the server. */
  8. class Subject {
  9. constructor() {
  10. this.observers = [];
  11. }
  12. next(item) {
  13. for (const observer of this.observers) {
  14. observer.next(item);
  15. }
  16. }
  17. error(err) {
  18. for (const observer of this.observers) {
  19. if (observer.error) {
  20. observer.error(err);
  21. }
  22. }
  23. }
  24. complete() {
  25. for (const observer of this.observers) {
  26. if (observer.complete) {
  27. observer.complete();
  28. }
  29. }
  30. }
  31. subscribe(observer) {
  32. this.observers.push(observer);
  33. return new Utils_1.SubjectSubscription(this, observer);
  34. }
  35. }
  36. exports.Subject = Subject;
  37. //# sourceMappingURL=Subject.js.map