'use strict'; function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _createClass(e, r, t) { return Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } var TransactionImpl = /*#__PURE__*/_createClass(function TransactionImpl(signal) { var _this = this; _classCallCheck(this, TransactionImpl); _defineProperty(this, "act", function (action) { var cleanup = action(); if (cleanup) { _this.signal.addEventListener('abort', cleanup); } }); this.signal = signal; }); function transaction(signal) { return new TransactionImpl(signal); } function createSignalSwitch(signal) { var controller = null; function recreateChildSignal() { var _controller; (_controller = controller) === null || _controller === void 0 || _controller.abort(); controller = new AbortController(); return AbortSignal.any([signal, controller.signal]); } function wrapper(fn) { if (!fn) { return function () { return recreateChildSignal(); }; } return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return fn.apply(void 0, [recreateChildSignal()].concat(args)); }; } return wrapper; } exports.createSignalSwitch = createSignalSwitch; exports.transaction = transaction;