index.js 1.5 KB

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