@ives_xxz/framework 2.0.14 → 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.
@@ -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.PromiseResult<T>> {
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.PromiseResult<T>> => {
141
- return new Promise<FW.PromiseResult<T>>((resolve, reject) => {
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.PromiseResult<T> = {
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
- result.cancelled.push(
191
- ...promises
192
- .map((p) => p.id)
193
- .filter(
194
- (id) =>
195
- !result.success.some((s) => s.id === id) &&
196
- !result.failed.some((f) => f.id === id),
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(value);
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.PromiseResult<T>> = {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
@@ -83,7 +83,6 @@ class MockWebSocket {
83
83
 
84
84
  class WebSocketMockServer {
85
85
  private clients: Set<MockWebSocket> = new Set();
86
- private broadcastIntervals: any[] = [];
87
86
  private static instance: WebSocketMockServer;
88
87
 
89
88
  public mockResponses = {};
@@ -161,8 +160,6 @@ class WebSocketMockServer {
161
160
  }
162
161
 
163
162
  public stop(): void {
164
- this.broadcastIntervals.forEach((interval) => clearInterval(interval));
165
- this.broadcastIntervals = [];
166
163
  this.clients.clear();
167
164
  FW.Log.system('🛑 WebSocket 模拟服务器已停止');
168
165
  }
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 PromiseResult<T = any> = {
1843
- success: PromiseProxy<T>[];
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