@nu-art/ts-common 0.202.101 → 0.202.102
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.
- package/package.json +1 -1
- package/utils/array-tools.d.ts +1 -0
- package/utils/array-tools.js +15 -1
- package/utils/queue.d.ts +3 -3
- package/utils/queue.js +10 -10
package/package.json
CHANGED
package/utils/array-tools.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare function removeFromArray<T>(array: T[], item: (_item: T) => boole
|
|
|
18
18
|
* tested V
|
|
19
19
|
*/
|
|
20
20
|
export declare function removeFromArrayByIndex<T>(array: T[], index: number): T[];
|
|
21
|
+
export declare function swapInArrayByIndex<T>(array: T[], i1: number, i2: number): T[];
|
|
21
22
|
/**
|
|
22
23
|
* Deprecated
|
|
23
24
|
*/
|
package/utils/array-tools.js
CHANGED
|
@@ -26,9 +26,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.arrayIncludesAll = exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
|
|
29
|
+
exports.arrayIncludesAll = exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.swapInArrayByIndex = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
|
|
30
30
|
const tools_1 = require("./tools");
|
|
31
31
|
const object_tools_1 = require("./object-tools");
|
|
32
|
+
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
32
33
|
function filterInOut(input, filter) {
|
|
33
34
|
return {
|
|
34
35
|
filteredIn: input.filter(filter),
|
|
@@ -64,6 +65,19 @@ function removeFromArrayByIndex(array, index) {
|
|
|
64
65
|
return array;
|
|
65
66
|
}
|
|
66
67
|
exports.removeFromArrayByIndex = removeFromArrayByIndex;
|
|
68
|
+
function swapInArrayByIndex(array, i1, i2) {
|
|
69
|
+
if (i1 < 0 || i1 >= array.length)
|
|
70
|
+
throw new exceptions_1.BadImplementationException(`index i1 out of bounds: ${i1}`);
|
|
71
|
+
if (i2 < 0 || i2 >= array.length)
|
|
72
|
+
throw new exceptions_1.BadImplementationException(`index i2 out of bounds: ${i2}`);
|
|
73
|
+
if (i1 === i2)
|
|
74
|
+
return array;
|
|
75
|
+
const temp = array[i1];
|
|
76
|
+
array[i1] = array[i2];
|
|
77
|
+
array[i2] = temp;
|
|
78
|
+
return array;
|
|
79
|
+
}
|
|
80
|
+
exports.swapInArrayByIndex = swapInArrayByIndex;
|
|
67
81
|
/**
|
|
68
82
|
* Deprecated
|
|
69
83
|
*/
|
package/utils/queue.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Logger } from
|
|
1
|
+
import { Logger } from '../core/logger/Logger';
|
|
2
2
|
export declare class Queue extends Logger {
|
|
3
|
-
private
|
|
4
|
-
private
|
|
3
|
+
private allowedParallelOperationsCount;
|
|
4
|
+
private runningOperationsCount;
|
|
5
5
|
private queue;
|
|
6
6
|
private onQueueEmpty?;
|
|
7
7
|
private finalResolve?;
|
package/utils/queue.js
CHANGED
|
@@ -32,14 +32,14 @@ const array_tools_1 = require("./array-tools");
|
|
|
32
32
|
class Queue extends Logger_1.Logger {
|
|
33
33
|
constructor(name) {
|
|
34
34
|
super(name);
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
35
|
+
this.allowedParallelOperationsCount = 1;
|
|
36
|
+
this.runningOperationsCount = 0;
|
|
37
37
|
this.queue = [];
|
|
38
38
|
this.ignore = () => {
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
setParallelCount(parallelCount) {
|
|
42
|
-
this.
|
|
42
|
+
this.allowedParallelOperationsCount = parallelCount;
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
45
|
setOnQueueEmpty(onQueueEmpty) {
|
|
@@ -52,7 +52,7 @@ class Queue extends Logger_1.Logger {
|
|
|
52
52
|
}
|
|
53
53
|
addItemImpl(toExecute, onCompleted, onError) {
|
|
54
54
|
(0, array_tools_1.addItemToArray)(this.queue, (resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
this.
|
|
55
|
+
this.runningOperationsCount++;
|
|
56
56
|
try {
|
|
57
57
|
const output = yield toExecute();
|
|
58
58
|
onCompleted && onCompleted(output);
|
|
@@ -62,23 +62,23 @@ class Queue extends Logger_1.Logger {
|
|
|
62
62
|
onError && onError(e);
|
|
63
63
|
}
|
|
64
64
|
catch (e1) {
|
|
65
|
-
this.logError(
|
|
66
|
-
this.logError(
|
|
67
|
-
this.logError(
|
|
65
|
+
this.logError('Error while calling onError');
|
|
66
|
+
this.logError('--- Original: ', e);
|
|
67
|
+
this.logError('-- Secondary: ', e1);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
this.
|
|
70
|
+
this.runningOperationsCount--;
|
|
71
71
|
resolve();
|
|
72
72
|
this.execute();
|
|
73
73
|
}));
|
|
74
74
|
}
|
|
75
75
|
execute() {
|
|
76
76
|
var _a;
|
|
77
|
-
if (this.queue.length === 0 && this.
|
|
77
|
+
if (this.queue.length === 0 && this.runningOperationsCount === 0) {
|
|
78
78
|
this.onQueueEmpty && this.onQueueEmpty();
|
|
79
79
|
return (_a = this.finalResolve) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
80
80
|
}
|
|
81
|
-
for (let i = 0; this.
|
|
81
|
+
for (let i = 0; this.runningOperationsCount < this.allowedParallelOperationsCount && i < this.queue.length; i++) {
|
|
82
82
|
const toExecute = this.queue[0];
|
|
83
83
|
(0, array_tools_1.removeItemFromArray)(this.queue, toExecute);
|
|
84
84
|
new Promise(toExecute.bind(this))
|