utiller 1.0.78 → 1.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,7 +97,7 @@ var ERRORs = {
97
97
  message: "assign task timeout happen"
98
98
  },
99
99
  4011: {
100
- message: "\u4E0D\u80FD\u8D70\u5230\u9019\u88E1, \u76EE\u524D\u88AB\u52D5\u5F0F\u7684\u6A5F\u5236\u53EA\u652F\u63F4runByEachTask"
100
+ message: "\u4E0D\u80FD\u8D70\u5230\u9019\u88E1, \u76EE\u524D\u88AB\u52D5\u5F0F\u7684\u6A5F\u5236\u53EA\u652F\u63F4runByEachTask, runByParams"
101
101
  },
102
102
  8001: {
103
103
  message: "append file fail"
@@ -83,6 +83,7 @@ var InfinitePool = /*#__PURE__*/function () {
83
83
  var maxWorkers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _configerer.configerer.POOLLER_WORKER_DEFAULT;
84
84
  var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _index2.utiller.getRandomValue(0, 100000000000);
85
85
  (0, _classCallCheck2["default"])(this, InfinitePool);
86
+ (0, _defineProperty2["default"])(this, "isRunInBackgroundMode", false);
86
87
  (0, _defineProperty2["default"])(this, "state", _configerer.configerer.POOLLER_STATE.RUN_BY_EACH_TASK);
87
88
  (0, _defineProperty2["default"])(this, "enableOfTaskSleepByInterval", _configerer.configerer.POOLLER_ENABLE_TASK_SLEEP_BY_INTERVAL);
88
89
  (0, _defineProperty2["default"])(this, "taskSleepInterval", _configerer.configerer.POOLLER_TASK_OF_INTERVAL_DEFAULT);
@@ -146,7 +147,6 @@ var InfinitePool = /*#__PURE__*/function () {
146
147
  });
147
148
  (0, _defineProperty2["default"])(this, "getCountOfAssignTaskInQueue", function () {
148
149
  var size = 0;
149
- if (_this.state === _configerer.configerer.POOLLER_STATE.RUN_BY_PARAMS) return _this.queueOfWaitingParam.length;
150
150
 
151
151
  var _iterator = _createForOfIteratorHelper(_configerer.configerer.POOLLER_PRIORITY),
152
152
  _step;
@@ -381,69 +381,69 @@ var InfinitePool = /*#__PURE__*/function () {
381
381
  return _lodash["default"].size(_this.queueOfExecutingTask) === 0;
382
382
  });
383
383
  (0, _defineProperty2["default"])(this, "appendParamInToQueue", function () {
384
- for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
385
- params[_key] = arguments[_key];
386
- }
384
+ var _this$queueOfWaitingP;
387
385
 
388
- for (var _i = 0, _params = params; _i < _params.length; _i++) {
389
- var param = _params[_i];
386
+ _this.triggerBgInstance();
390
387
 
391
- _this.queueOfWaitingParam.push(param);
392
- }
388
+ (_this$queueOfWaitingP = _this.queueOfWaitingParam).push.apply(_this$queueOfWaitingP, arguments);
393
389
  });
394
390
  (0, _defineProperty2["default"])(this, "runByParams", /*#__PURE__*/function () {
395
391
  var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(functionOfAsyncTask) {
396
- var _len2,
392
+ var _len,
397
393
  params,
398
- _key2,
394
+ _key,
399
395
  _args3 = arguments;
400
396
 
401
397
  return _regenerator["default"].wrap(function _callee3$(_context3) {
402
398
  while (1) {
403
399
  switch (_context3.prev = _context3.next) {
404
400
  case 0:
405
- for (_len2 = _args3.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
406
- params[_key2 - 1] = _args3[_key2];
401
+ for (_len = _args3.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
402
+ params[_key - 1] = _args3[_key];
403
+ }
404
+
405
+ if (functionOfAsyncTask === undefined) {
406
+ functionOfAsyncTask = _this.queueOfAssignTask["low"].shift().task;
407
407
  }
408
408
 
409
409
  if (_lodash["default"].isFunction(functionOfAsyncTask)) {
410
- _context3.next = 3;
410
+ _context3.next = 4;
411
411
  break;
412
412
  }
413
413
 
414
414
  throw new _exceptioner["default"](4006, "runByParams error, typeof task can't be ".concat((0, _typeof2["default"])(functionOfAsyncTask)));
415
415
 
416
- case 3:
416
+ case 4:
417
417
  if (_lodash["default"].isArray(params)) {
418
- _context3.next = 5;
418
+ _context3.next = 6;
419
419
  break;
420
420
  }
421
421
 
422
422
  throw new _exceptioner["default"](4006, "runByParams error, typeof params can't be ".concat((0, _typeof2["default"])(params)));
423
423
 
424
- case 5:
425
- _this.appendParamInToQueue.apply(_this, params);
424
+ case 6:
425
+ _this.beforeRun();
426
426
 
427
427
  _this.add(functionOfAsyncTask);
428
428
 
429
- _this.setState(_configerer.configerer.POOLLER_STATE.RUN_BY_PARAMS);
429
+ _this.appendParamInToQueue.apply(_this, params);
430
430
 
431
- _this.beforeRun();
431
+ _this.setState(_configerer.configerer.POOLLER_STATE.RUN_BY_PARAMS);
432
432
 
433
- case 9:
433
+ case 10:
434
434
  if (!(_this.ruleOfInfiniteRun() && _lodash["default"].size(_this.queueOfWaitingParam) > 0)) {
435
- _context3.next = 14;
435
+ _context3.next = 15;
436
436
  break;
437
437
  }
438
438
 
439
- _context3.next = 12;
439
+ _context3.next = 13;
440
440
  return (0, _classPrivateFieldGet2["default"])(_this, _run).call(_this);
441
441
 
442
- case 12:
443
- _context3.next = 9;
442
+ case 13:
443
+ _context3.next = 10;
444
444
  break;
445
445
 
446
- case 14:
446
+ case 15:
447
447
  case "end":
448
448
  return _context3.stop();
449
449
  }
@@ -455,16 +455,6 @@ var InfinitePool = /*#__PURE__*/function () {
455
455
  return _ref3.apply(this, arguments);
456
456
  };
457
457
  }());
458
- (0, _defineProperty2["default"])(this, "runByEachTaskInBackGround", function () {
459
- if (_this.atomicBgInstance !== undefined) clearTimeout(_this.atomicBgInstance);
460
- _this.atomicBgInstance = _this.runInBackGround(_this.runByEachTask);
461
- /**
462
- * 因為偷懶, 所以回傳整個instance, 這樣程式碼就只要寫一行
463
- * const pool = new InfinitePool(1).runByEachTaskInBackGround();
464
- */
465
-
466
- return _this;
467
- });
468
458
  (0, _defineProperty2["default"])(this, "runByEachTask", /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
469
459
  var tasks,
470
460
  _args4 = arguments;
@@ -550,10 +540,12 @@ var InfinitePool = /*#__PURE__*/function () {
550
540
  };
551
541
  }());
552
542
  (0, _defineProperty2["default"])(this, "runInBackGround", function (asyncfunc) {
553
- for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
554
- params[_key3 - 1] = arguments[_key3];
543
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
544
+ params[_key2 - 1] = arguments[_key2];
555
545
  }
556
546
 
547
+ _this.isRunInBackgroundMode = true;
548
+
557
549
  if (!(typeof asyncfunc === "function")) {
558
550
  throw new _exceptioner["default"](4002, "_asyncfunc can't be ".concat((0, _typeof2["default"])(asyncfunc)));
559
551
  }
@@ -723,7 +715,7 @@ var InfinitePool = /*#__PURE__*/function () {
723
715
  break;
724
716
 
725
717
  case 13:
726
- _index2.utiller.appendInfo(_this.getPoollerLogFormat("4574152 \u4E0D\u61C9\u8A72\u8D70\u5230\u9019\u88CF,\u4F46\u662F minor issue"));
718
+ _this.printLogMessage("4574152 \u4E0D\u61C9\u8A72\u8D70\u5230\u9019\u88CF,\u4F46\u662F minor issue", true);
727
719
 
728
720
  case 14:
729
721
  if (_this.queueOfExecutingTask.length > _this.maxWorker) _this.printLogMessage("4512214 \u4E00\u5B9A\u662F\u6539\u58DE\u4E86!!!!!!!!!!, ".concat(_this.getLogMessageOfExecutingTaskQueueCount, " "), true);
@@ -799,17 +791,37 @@ var InfinitePool = /*#__PURE__*/function () {
799
791
  (0, _defineProperty2["default"])(this, "runInfiniteInBackground", function (functionOfAsyncTask, interval) {
800
792
  _this.runInBackGround(_this.runInInfinite, functionOfAsyncTask, interval);
801
793
  });
802
- (0, _defineProperty2["default"])(this, "runByParamInBackground", function (functionOfAsyncTask) {
803
- for (var _len4 = arguments.length, params = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
804
- params[_key4 - 1] = arguments[_key4];
794
+ (0, _defineProperty2["default"])(this, "runByParamInBackGround", function (functionOfAsyncTask) {
795
+ for (var _len3 = arguments.length, params = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
796
+ params[_key3 - 1] = arguments[_key3];
805
797
  }
806
798
 
807
- _this.runInBackGround.apply(_this, [_this.runByParams, functionOfAsyncTask].concat(params));
799
+ return _this.invokeInstanceOfBackground.apply(_this, [_this.runByParams, functionOfAsyncTask].concat(params));
800
+ });
801
+ (0, _defineProperty2["default"])(this, "runByTimesInBackGround", function (functionOfAsyncTask, times) {
802
+ _this.runInBackGround(_this.runByTimes, functionOfAsyncTask, times);
808
803
 
809
804
  return _this;
810
805
  });
811
- (0, _defineProperty2["default"])(this, "runByTimesInBackground", function (functionOfAsyncTask, times) {
812
- _this.runInBackGround(_this.runByTimes, functionOfAsyncTask, times);
806
+ (0, _defineProperty2["default"])(this, "runByEachTaskInBackGround", function () {
807
+ for (var _len4 = arguments.length, params = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
808
+ params[_key4] = arguments[_key4];
809
+ }
810
+
811
+ return _this.invokeInstanceOfBackground.apply(_this, [_this.runByEachTask].concat(params));
812
+ });
813
+ (0, _defineProperty2["default"])(this, "invokeInstanceOfBackground", function (state) {
814
+ if (_this.atomicBgInstance !== undefined) clearTimeout(_this.atomicBgInstance);
815
+
816
+ for (var _len5 = arguments.length, params = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
817
+ params[_key5 - 1] = arguments[_key5];
818
+ }
819
+
820
+ _this.atomicBgInstance = _this.runInBackGround.apply(_this, [state].concat(params));
821
+ /**
822
+ * 因為偷懶, 所以回傳整個instance, 這樣程式碼就只要寫一行
823
+ * const pool = new InfinitePool(1).runByEachTaskInBackGround();
824
+ */
813
825
 
814
826
  return _this;
815
827
  });
@@ -862,8 +874,8 @@ var InfinitePool = /*#__PURE__*/function () {
862
874
  value: function printLogMessage(message) {
863
875
  var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
864
876
 
865
- for (var _len5 = arguments.length, infos = new Array(_len5 > 2 ? _len5 - 2 : 0), _key5 = 2; _key5 < _len5; _key5++) {
866
- infos[_key5 - 2] = arguments[_key5];
877
+ for (var _len6 = arguments.length, infos = new Array(_len6 > 2 ? _len6 - 2 : 0), _key6 = 2; _key6 < _len6; _key6++) {
878
+ infos[_key6 - 2] = arguments[_key6];
867
879
  }
868
880
 
869
881
  if (SPECIFICITY_DEBUG) _index2.utiller.printLogMessage.apply(_index2.utiller, [this.getPoollerLogFormat(message), error].concat(infos));
@@ -927,7 +939,7 @@ var InfinitePool = /*#__PURE__*/function () {
927
939
  case 0:
928
940
  priority = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : "low";
929
941
  taskName = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : "noName";
930
- this.trigger();
942
+ this.triggerBgInstance();
931
943
  return _context9.abrupt("return", new Promise(function (resolve, reject) {
932
944
  var callbackWrapper = function callbackWrapper(result) {
933
945
  if (result.assignedTaskCompleted) {
@@ -1038,9 +1050,9 @@ var InfinitePool = /*#__PURE__*/function () {
1038
1050
  /** 加上一個 被動式啟動, 不然一直while() run, 可能有效能上的問題,現階端只支援RUN_BY_TASK */
1039
1051
 
1040
1052
  }, {
1041
- key: "trigger",
1042
- value: function trigger() {
1043
- if (this.isQueuePolling) {
1053
+ key: "triggerBgInstance",
1054
+ value: function triggerBgInstance() {
1055
+ if (!this.isRunInBackgroundMode || this.isQueuePolling) {
1044
1056
  return;
1045
1057
  }
1046
1058
 
@@ -1048,6 +1060,9 @@ var InfinitePool = /*#__PURE__*/function () {
1048
1060
  /** 因為不這樣做, 就會產生 race condition, 會產生出3個runInBackGround instance */
1049
1061
  this.runByEachTaskInBackGround();
1050
1062
  return;
1063
+ } else if (this.state === _configerer.configerer.POOLLER_STATE.RUN_BY_PARAMS) {
1064
+ this.runByParamInBackGround();
1065
+ return;
1051
1066
  }
1052
1067
 
1053
1068
  throw new _exceptioner["default"](4011, "this.state is ==> ".concat(_index2.utiller.getItsKeyByValue(_configerer.configerer.POOLLER_STATE, this.state)));
@@ -1139,7 +1154,7 @@ var InfinitePool = /*#__PURE__*/function () {
1139
1154
  return this.mapOfHashNCallbackWrapper[hash] !== undefined;
1140
1155
  }
1141
1156
  }, {
1142
- key: "exampleOfWait4ResultAndRunInBackground",
1157
+ key: "exampleOfRunByTaskWait4ResultAndRunInBackground",
1143
1158
  value:
1144
1159
  /** following function are examples **/
1145
1160
 
@@ -1147,13 +1162,9 @@ var InfinitePool = /*#__PURE__*/function () {
1147
1162
 
1148
1163
  /** following function are examples **/
1149
1164
 
1150
- /** following function are examples **/
1151
-
1152
- /** following function are examples **/
1153
-
1154
1165
  /** following function are examples **/
1155
1166
  function () {
1156
- var _exampleOfWait4ResultAndRunInBackground = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
1167
+ var _exampleOfRunByTaskWait4ResultAndRunInBackground = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
1157
1168
  var pool, asyncTask, startTimoutTask;
1158
1169
  return _regenerator["default"].wrap(function _callee13$(_context13) {
1159
1170
  while (1) {
@@ -1231,11 +1242,10 @@ var InfinitePool = /*#__PURE__*/function () {
1231
1242
  break;
1232
1243
  }
1233
1244
 
1234
- _index2.utiller.appendInfo("system is running");
1235
-
1245
+ console.log("system is running");
1236
1246
  pool.showState();
1237
1247
  _context13.next = 15;
1238
- return _index2.utiller.syncDelay(5000);
1248
+ return _index2.utiller.syncDelay(1000);
1239
1249
 
1240
1250
  case 15:
1241
1251
  _context13.next = 10;
@@ -1249,11 +1259,11 @@ var InfinitePool = /*#__PURE__*/function () {
1249
1259
  }, _callee13);
1250
1260
  }));
1251
1261
 
1252
- function exampleOfWait4ResultAndRunInBackground() {
1253
- return _exampleOfWait4ResultAndRunInBackground.apply(this, arguments);
1262
+ function exampleOfRunByTaskWait4ResultAndRunInBackground() {
1263
+ return _exampleOfRunByTaskWait4ResultAndRunInBackground.apply(this, arguments);
1254
1264
  }
1255
1265
 
1256
- return exampleOfWait4ResultAndRunInBackground;
1266
+ return exampleOfRunByTaskWait4ResultAndRunInBackground;
1257
1267
  }()
1258
1268
  }, {
1259
1269
  key: "exampleOfRunInBackgroundInfinite",
@@ -1405,7 +1415,7 @@ var InfinitePool = /*#__PURE__*/function () {
1405
1415
  switch (_context20.prev = _context20.next) {
1406
1416
  case 0:
1407
1417
  pool = new InfinitePool(5);
1408
- pool.runByParamInBackground( /*#__PURE__*/function () {
1418
+ pool.runByParamInBackGround( /*#__PURE__*/function () {
1409
1419
  var _ref11 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(param) {
1410
1420
  var ms;
1411
1421
  return _regenerator["default"].wrap(function _callee19$(_context19) {
@@ -1431,23 +1441,26 @@ var InfinitePool = /*#__PURE__*/function () {
1431
1441
  return _ref11.apply(this, arguments);
1432
1442
  };
1433
1443
  }(), "david", "susan", "golden", "weber", "kevin");
1444
+ setTimeout(function () {
1445
+ pool.appendParamInToQueue("apple", "Rui");
1446
+ }, 12000);
1434
1447
 
1435
- case 2:
1448
+ case 3:
1436
1449
  if (!pool.isRunning()) {
1437
- _context20.next = 8;
1450
+ _context20.next = 9;
1438
1451
  break;
1439
1452
  }
1440
1453
 
1441
1454
  _index2.utiller.appendInfo("system is running");
1442
1455
 
1443
- _context20.next = 6;
1456
+ _context20.next = 7;
1444
1457
  return _index2.utiller.syncDelay(3000);
1445
1458
 
1446
- case 6:
1447
- _context20.next = 2;
1459
+ case 7:
1460
+ _context20.next = 3;
1448
1461
  break;
1449
1462
 
1450
- case 8:
1463
+ case 9:
1451
1464
  case "end":
1452
1465
  return _context20.stop();
1453
1466
  }
@@ -1472,7 +1485,7 @@ var InfinitePool = /*#__PURE__*/function () {
1472
1485
  case 0:
1473
1486
  pool = new InfinitePool(6);
1474
1487
  count = 0;
1475
- pool.runByTimesInBackground( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21() {
1488
+ pool.runByTimesInBackGround( /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21() {
1476
1489
  var ms;
1477
1490
  return _regenerator["default"].wrap(function _callee21$(_context21) {
1478
1491
  while (1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.78",
3
+ "version": "1.0.79",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "configerer": "^1.0.11",
14
- "utiller": "^1.0.77",
14
+ "utiller": "^1.0.78",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.9",
17
17
  "lodash": "^4.17.20",