@ives_xxz/framework 2.0.15 → 2.0.17

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/Framework.ts CHANGED
@@ -219,7 +219,6 @@ export class Framework implements FW.Framework {
219
219
  defaultScope: 'Singleton',
220
220
  autoBindInjectable: true,
221
221
  });
222
-
223
222
  this.reregisterAllComponents();
224
223
  }
225
224
 
@@ -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,
@@ -22,10 +22,10 @@ export default class FWSocketManager extends FWManager implements FW.SocketManag
22
22
  async createSocket(
23
23
  tag: string,
24
24
  address: string,
25
- sender: FW.SocketSender,
26
- handle: FW.SocketHandle,
25
+ sender: FW.Sender,
26
+ handle: FW.Handle,
27
27
  config: FW.SocketConfig,
28
- ) {
28
+ ): Promise<FW.Socket> {
29
29
  const proxy = new FWSocket().createSocket(address, tag, sender, handle, {
30
30
  heartTimeout: config.heartTimeout,
31
31
  heartWeakTime: config.heartWeakTime,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.0.15",
3
+ "version": "2.0.17",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
package/types/FW.d.ts CHANGED
@@ -1837,11 +1837,9 @@ declare namespace FW {
1837
1837
  retryCondition?: (error: any, retryCount: number) => boolean;
1838
1838
  };
1839
1839
 
1840
- type Promise = (resolve: (value: any) => void, reject: (reason?: any) => void) => void;
1841
-
1842
- type PromiseResult<T = any> = {
1843
- success: PromiseProxy<T>[];
1844
- failed: { id: number; reason: any }[];
1840
+ type PromiseAllResult<T = any> = {
1841
+ success: Array<{ id: number; value: T }>;
1842
+ failed: Array<{ id: number; reason: any }>;
1845
1843
  cancelled: number[];
1846
1844
  };
1847
1845
 
@@ -2301,12 +2299,12 @@ declare namespace FW {
2301
2299
  initialize?();
2302
2300
  onDestroy?();
2303
2301
  onWeakNetWork?(): void;
2304
- abstract onMessage(msg: any): void;
2305
2302
  onHeart?(msg: any): Promise<boolean>;
2306
2303
  onClose?(): void;
2307
2304
  onOpen?(): void;
2308
2305
  onError?(msg: any): void;
2309
2306
  onTimeout?(): void;
2307
+ abstract onMessage(msg: any): void;
2310
2308
  abstract getProtocolKey?(msg: any): string;
2311
2309
  abstract onBeforeReceivingMessage?(msg: any): Promise<FW.SocketMessage>;
2312
2310
  }
@@ -2317,7 +2315,8 @@ declare namespace FW {
2317
2315
  public abstract initialize(): void;
2318
2316
  public abstract onDestroy(): void;
2319
2317
  }
2320
- export class Http extends FWService {
2318
+
2319
+ export class Http extends Service {
2321
2320
  public initialize() {}
2322
2321
  public onDestroy(): void {}
2323
2322
 
@@ -2342,7 +2341,6 @@ declare namespace FW {
2342
2341
 
2343
2342
  declare namespace FW {
2344
2343
  export class SocketMock {
2345
- static createMockData<T>(msgId: string, data: T);
2346
2344
  public static start(mockResponses: {}): void;
2347
2345
  public static stop(): void;
2348
2346
  }