index.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var createAdapter = function () {
  2. var sinks = [];
  3. return [function (a) { return broadcast(sinks, a); }, new FanoutPortStream(sinks)];
  4. };
  5. var broadcast = function (sinks, a) {
  6. return sinks.slice().forEach(function (_a) {
  7. var sink = _a.sink, scheduler = _a.scheduler;
  8. return tryEvent(scheduler.currentTime(), a, sink);
  9. });
  10. };
  11. var FanoutPortStream = /** @class */ (function () {
  12. function FanoutPortStream(sinks) {
  13. this.sinks = sinks;
  14. }
  15. FanoutPortStream.prototype.run = function (sink, scheduler) {
  16. var s = { sink: sink, scheduler: scheduler };
  17. this.sinks.push(s);
  18. return new RemovePortDisposable(s, this.sinks);
  19. };
  20. return FanoutPortStream;
  21. }());
  22. var RemovePortDisposable = /** @class */ (function () {
  23. function RemovePortDisposable(sink, sinks) {
  24. this.sink = sink;
  25. this.sinks = sinks;
  26. }
  27. RemovePortDisposable.prototype.dispose = function () {
  28. var i = this.sinks.indexOf(this.sink);
  29. if (i >= 0) {
  30. this.sinks.splice(i, 1);
  31. }
  32. };
  33. return RemovePortDisposable;
  34. }());
  35. function tryEvent(t, a, sink) {
  36. try {
  37. sink.event(t, a);
  38. }
  39. catch (e) {
  40. sink.error(t, e);
  41. }
  42. }
  43. export { FanoutPortStream, RemovePortDisposable, createAdapter };
  44. //# sourceMappingURL=index.mjs.map