Subject.js 938 B

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