@ives_xxz/framework 2.0.15 → 2.0.16
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/manager/FWPromiseManager.ts +21 -18
- package/package.json +1 -1
- package/types/FW.d.ts +3 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FWManager } from './FWManager';
|
|
2
2
|
|
|
3
3
|
export default class FWPromiseManager extends FWManager implements FW.PromiseManager {
|
|
4
|
-
private promiseRegistry: Map<number, FW.PromiseProxy
|
|
4
|
+
private promiseRegistry: Map<number, FW.PromiseProxy<any>>;
|
|
5
5
|
private uniqueId: number = 0;
|
|
6
6
|
|
|
7
7
|
public initialize(): void {
|
|
8
|
-
this.promiseRegistry = new Map<number, FW.PromiseProxy
|
|
8
|
+
this.promiseRegistry = new Map<number, FW.PromiseProxy<any>>();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
public onDestroy(): void {
|
|
@@ -129,7 +129,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
129
129
|
public all<T = any>(
|
|
130
130
|
promises: FW.PromiseProxy<T>[],
|
|
131
131
|
options: FW.PromiseExecuteOptions = {},
|
|
132
|
-
): FW.PromiseProxy<FW.
|
|
132
|
+
): FW.PromiseProxy<FW.PromiseAllResult<T>> {
|
|
133
133
|
const id = this.uniqueId++;
|
|
134
134
|
const abortController = new AbortController();
|
|
135
135
|
const maxRetryTimes = options.retryCount || 0;
|
|
@@ -137,8 +137,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
137
137
|
let timerSchedule: FW.TimerSchedule;
|
|
138
138
|
let retryCount = 0;
|
|
139
139
|
|
|
140
|
-
const createPromise = (): Promise<FW.
|
|
141
|
-
return new Promise<FW.
|
|
140
|
+
const createPromise = (): Promise<FW.PromiseAllResult<T>> => {
|
|
141
|
+
return new Promise<FW.PromiseAllResult<T>>((resolve, reject) => {
|
|
142
142
|
if (options.timeout && options.timeout > 0) {
|
|
143
143
|
timerSchedule?.unSchedule();
|
|
144
144
|
timerSchedule = FW.Entry.timeMgr.scheduleOnce(() => {
|
|
@@ -178,8 +178,8 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
178
178
|
|
|
179
179
|
abortController.signal.addEventListener('abort', onAbort);
|
|
180
180
|
|
|
181
|
-
const processAll = async () => {
|
|
182
|
-
const result: FW.
|
|
181
|
+
const processAll = async (): Promise<FW.PromiseAllResult<T>> => {
|
|
182
|
+
const result: FW.PromiseAllResult<T> = {
|
|
183
183
|
success: [],
|
|
184
184
|
failed: [],
|
|
185
185
|
cancelled: [],
|
|
@@ -187,21 +187,24 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
187
187
|
|
|
188
188
|
for (const promiseProxy of promises) {
|
|
189
189
|
if (abortController.signal.aborted) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
(id)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
);
|
|
190
|
+
// 找出所有尚未处理的任务标记为取消
|
|
191
|
+
const remainingIds = promises
|
|
192
|
+
.filter(
|
|
193
|
+
(p) =>
|
|
194
|
+
!result.success.some((s) => s.id === p.id) &&
|
|
195
|
+
!result.failed.some((f) => f.id === p.id),
|
|
196
|
+
)
|
|
197
|
+
.map((p) => p.id);
|
|
198
|
+
result.cancelled.push(...remainingIds);
|
|
199
199
|
break;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
try {
|
|
203
203
|
const value = await promiseProxy.promise;
|
|
204
|
-
result.success.push(
|
|
204
|
+
result.success.push({
|
|
205
|
+
id: promiseProxy.id,
|
|
206
|
+
value: value,
|
|
207
|
+
});
|
|
205
208
|
} catch (error) {
|
|
206
209
|
if (promiseProxy.status === FW.SystemDefine.FWPromiseStatus.CANCELLED) {
|
|
207
210
|
result.cancelled.push(promiseProxy.id);
|
|
@@ -256,7 +259,7 @@ export default class FWPromiseManager extends FWManager implements FW.PromiseMan
|
|
|
256
259
|
};
|
|
257
260
|
|
|
258
261
|
const promise = createPromise();
|
|
259
|
-
const promiseProxy: FW.PromiseProxy<FW.
|
|
262
|
+
const promiseProxy: FW.PromiseProxy<FW.PromiseAllResult<T>> = {
|
|
260
263
|
id,
|
|
261
264
|
promise,
|
|
262
265
|
status: FW.SystemDefine.FWPromiseStatus.PENDING,
|
package/package.json
CHANGED
package/types/FW.d.ts
CHANGED
|
@@ -1839,9 +1839,9 @@ declare namespace FW {
|
|
|
1839
1839
|
|
|
1840
1840
|
type Promise = (resolve: (value: any) => void, reject: (reason?: any) => void) => void;
|
|
1841
1841
|
|
|
1842
|
-
type
|
|
1843
|
-
success:
|
|
1844
|
-
failed: { id: number; reason: any }
|
|
1842
|
+
type PromiseAllResult<T = any> = {
|
|
1843
|
+
success: Array<{ id: number; value: T }>;
|
|
1844
|
+
failed: Array<{ id: number; reason: any }>;
|
|
1845
1845
|
cancelled: number[];
|
|
1846
1846
|
};
|
|
1847
1847
|
|