FunctionList.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __values = (this && this.__values) || function(o) {
  18. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  19. if (m) return m.call(o);
  20. if (o && typeof o.length === "number") return {
  21. next: function () {
  22. if (o && i >= o.length) o = void 0;
  23. return { value: o && o[i++], done: !o };
  24. }
  25. };
  26. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  27. };
  28. var __read = (this && this.__read) || function (o, n) {
  29. var m = typeof Symbol === "function" && o[Symbol.iterator];
  30. if (!m) return o;
  31. var i = m.call(o), r, ar = [], e;
  32. try {
  33. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  34. }
  35. catch (error) { e = { error: error }; }
  36. finally {
  37. try {
  38. if (r && !r.done && (m = i["return"])) m.call(i);
  39. }
  40. finally { if (e) throw e.error; }
  41. }
  42. return ar;
  43. };
  44. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  45. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  46. if (ar || !(i in from)) {
  47. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  48. ar[i] = from[i];
  49. }
  50. }
  51. return to.concat(ar || Array.prototype.slice.call(from));
  52. };
  53. Object.defineProperty(exports, "__esModule", { value: true });
  54. exports.FunctionList = void 0;
  55. var PrioritizedList_js_1 = require("./PrioritizedList.js");
  56. var FunctionList = (function (_super) {
  57. __extends(FunctionList, _super);
  58. function FunctionList() {
  59. return _super !== null && _super.apply(this, arguments) || this;
  60. }
  61. FunctionList.prototype.execute = function () {
  62. var e_1, _a;
  63. var data = [];
  64. for (var _i = 0; _i < arguments.length; _i++) {
  65. data[_i] = arguments[_i];
  66. }
  67. try {
  68. for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
  69. var item = _c.value;
  70. var result = item.item.apply(item, __spreadArray([], __read(data), false));
  71. if (result === false) {
  72. return false;
  73. }
  74. }
  75. }
  76. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  77. finally {
  78. try {
  79. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  80. }
  81. finally { if (e_1) throw e_1.error; }
  82. }
  83. return true;
  84. };
  85. FunctionList.prototype.asyncExecute = function () {
  86. var data = [];
  87. for (var _i = 0; _i < arguments.length; _i++) {
  88. data[_i] = arguments[_i];
  89. }
  90. var i = -1;
  91. var items = this.items;
  92. return new Promise(function (ok, fail) {
  93. (function execute() {
  94. var _a;
  95. while (++i < items.length) {
  96. var result = (_a = items[i]).item.apply(_a, __spreadArray([], __read(data), false));
  97. if (result instanceof Promise) {
  98. result.then(execute).catch(function (err) { return fail(err); });
  99. return;
  100. }
  101. if (result === false) {
  102. ok(false);
  103. return;
  104. }
  105. }
  106. ok(true);
  107. })();
  108. });
  109. };
  110. return FunctionList;
  111. }(PrioritizedList_js_1.PrioritizedList));
  112. exports.FunctionList = FunctionList;
  113. //# sourceMappingURL=FunctionList.js.map