1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports["default"] = exports.IterateProxyStrategy = void 0;
|
9 |
|
10 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
11 |
|
12 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
13 |
|
14 | var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
15 |
|
16 | var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
17 |
|
18 | var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
19 |
|
20 | var _err = _interopRequireDefault(require("@lskjs/err"));
|
21 |
|
22 | var _ProxyStrategy2 = require("./ProxyStrategy");
|
23 |
|
24 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
25 |
|
26 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
27 |
|
28 | var IterateProxyStrategy = function (_ProxyStrategy) {
|
29 | (0, _inherits2["default"])(IterateProxyStrategy, _ProxyStrategy);
|
30 |
|
31 | var _super = _createSuper(IterateProxyStrategy);
|
32 |
|
33 | function IterateProxyStrategy() {
|
34 | var _this;
|
35 |
|
36 | (0, _classCallCheck2["default"])(this, IterateProxyStrategy);
|
37 |
|
38 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
39 | args[_key] = arguments[_key];
|
40 | }
|
41 |
|
42 | _this = _super.call.apply(_super, [this].concat(args));
|
43 | _this.strategy = 'iterate';
|
44 | _this.iteration = 0;
|
45 | return _this;
|
46 | }
|
47 |
|
48 | (0, _createClass2["default"])(IterateProxyStrategy, [{
|
49 | key: "getProxy",
|
50 | value: function getProxy() {
|
51 | var list = this.getList();
|
52 | var fatalCount = this.getFatalCount();
|
53 | var count = list === null || list === void 0 ? void 0 : list.length;
|
54 | if (!count) throw new _err["default"]('PROXY_MANAGER_LIST_EMPTY', {
|
55 | count: count,
|
56 | fatalCount: fatalCount
|
57 | });
|
58 | this.iteration += 1;
|
59 | var nonFatalCount = count - fatalCount;
|
60 |
|
61 | return list[this.iteration % nonFatalCount];
|
62 | }
|
63 | }]);
|
64 | return IterateProxyStrategy;
|
65 | }(_ProxyStrategy2.ProxyStrategy);
|
66 |
|
67 | exports.IterateProxyStrategy = IterateProxyStrategy;
|
68 | var _default = IterateProxyStrategy;
|
69 | exports["default"] = _default;
|
70 |
|
\ | No newline at end of file |