@nu-art/ts-common 0.200.90 → 0.200.92
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/core/dispatcher.d.ts +2 -0
- package/core/dispatcher.js +18 -0
- package/package.json +1 -1
package/core/dispatcher.d.ts
CHANGED
|
@@ -9,10 +9,12 @@ export declare class Processor<T, K extends FunctionKeys<T>> extends Logger {
|
|
|
9
9
|
constructor(method: K);
|
|
10
10
|
processModules<R>(processor: (item: T) => R): R[];
|
|
11
11
|
processModulesAsync<R>(processor: (item: T) => Promise<R>): Promise<R[]>;
|
|
12
|
+
processModulesAsyncSerial<R>(processor: (item: T) => Promise<R>): Promise<R[]>;
|
|
12
13
|
filterModules(): any[];
|
|
13
14
|
}
|
|
14
15
|
export declare class Dispatcher<T, K extends FunctionKeys<T>, P extends ParamResolver<T, K> = ParamResolver<T, K>, R extends ReturnTypeResolver<T, K> = ReturnTypeResolver<T, K>> extends Processor<T, K> {
|
|
15
16
|
constructor(method: K);
|
|
16
17
|
dispatchModule(...p: P): R[];
|
|
17
18
|
dispatchModuleAsync(...p: P): Promise<R[]>;
|
|
19
|
+
dispatchModuleAsyncSerial(...p: P): Promise<R[]>;
|
|
18
20
|
}
|
package/core/dispatcher.js
CHANGED
|
@@ -42,6 +42,16 @@ class Processor extends Logger_1.Logger {
|
|
|
42
42
|
return Promise.all(this.filterModules().map(processor));
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
processModulesAsyncSerial(processor) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const modules = this.filterModules();
|
|
48
|
+
const toRet = [];
|
|
49
|
+
for (const module of modules) {
|
|
50
|
+
toRet.push(yield processor(module));
|
|
51
|
+
}
|
|
52
|
+
return toRet;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
45
55
|
filterModules() {
|
|
46
56
|
const listeners = Dispatcher.modulesResolver();
|
|
47
57
|
return listeners.filter(this.filter);
|
|
@@ -66,5 +76,13 @@ class Dispatcher extends Processor {
|
|
|
66
76
|
});
|
|
67
77
|
});
|
|
68
78
|
}
|
|
79
|
+
dispatchModuleAsyncSerial(...p) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
return this.processModulesAsync((listener) => {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
return listener[this.method](...p);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
69
87
|
}
|
|
70
88
|
exports.Dispatcher = Dispatcher;
|