@abtnode/core 1.17.3-beta-20251123-232619-53258789 → 1.17.3-beta-20251126-121502-d0926972

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.
@@ -25,7 +25,7 @@ const getValueFromEnvironments = (environments, key) => {
25
25
  const isAppObj = (x) => typeof x === 'object' && x !== null && !!x.meta;
26
26
 
27
27
  class ConfigSynchronizer {
28
- constructor({ manager, states, wait = 5000 }) {
28
+ constructor({ manager, states, wait = 2000 }) {
29
29
  this.manager = manager;
30
30
  this.wait = wait;
31
31
  this.throttles = new Map();
@@ -112,20 +112,54 @@ class ConfigSynchronizer {
112
112
  }
113
113
  }
114
114
 
115
- async throttledSyncAppConfig(did) {
115
+ async throttledSyncAppConfig(did, { wait = this.wait } = {}) {
116
116
  if (!this.throttles.has(did)) {
117
- this.throttles.set(
118
- did,
119
- throttle(
120
- async () => {
117
+ let pendingPromise = null;
118
+ let resolvePending = null;
119
+ let rejectPending = null;
120
+
121
+ const throttledFn = throttle(
122
+ async () => {
123
+ try {
121
124
  await this.syncAppConfig(did);
122
- this.throttles.get(did).cancel();
125
+ if (resolvePending) {
126
+ resolvePending();
127
+ resolvePending = null;
128
+ rejectPending = null;
129
+ }
130
+ } catch (error) {
131
+ if (rejectPending) {
132
+ rejectPending(error);
133
+ resolvePending = null;
134
+ rejectPending = null;
135
+ }
136
+ } finally {
137
+ throttledFn.cancel();
123
138
  this.throttles.delete(did);
124
- },
125
- this.wait,
126
- { leading: false }
127
- )
139
+ pendingPromise = null;
140
+ }
141
+ },
142
+ wait,
143
+ { leading: false, trailing: true }
128
144
  );
145
+
146
+ this.throttles.set(did, () => {
147
+ // 如果已经有待执行的 Promise,返回同一个
148
+ if (pendingPromise) {
149
+ return pendingPromise;
150
+ }
151
+
152
+ // 创建新的 Promise
153
+ pendingPromise = new Promise((resolve, reject) => {
154
+ resolvePending = resolve;
155
+ rejectPending = reject;
156
+ });
157
+
158
+ // 调用 throttle 函数
159
+ throttledFn();
160
+
161
+ return pendingPromise;
162
+ });
129
163
  }
130
164
  await this.throttles.get(did)();
131
165
  }
@@ -868,6 +868,35 @@ class DiskBlockletManager extends BaseBlockletManager {
868
868
  )
869
869
  );
870
870
 
871
+ // 如果只有 nonEntryComponent,没有 entry component,直接触发 started 事件并返回
872
+ if (componentDids.length === 0) {
873
+ const finalBlocklet = await this.getBlocklet(did);
874
+ await this.configSynchronizer.throttledSyncAppConfig(finalBlocklet);
875
+ const componentsInfo = getComponentsInternalInfo(finalBlocklet);
876
+ this.emit(BlockletInternalEvents.componentUpdated, {
877
+ appDid: blocklet.appDid,
878
+ components: componentsInfo,
879
+ });
880
+ this.emit(BlockletInternalEvents.componentStarted, {
881
+ appDid: blocklet.appDid,
882
+ components: nonEntryComponentIds.map((x) => ({ did: x })),
883
+ });
884
+ this.emit(BlockletEvents.statusChange, finalBlocklet);
885
+ this.emit(BlockletEvents.started, { ...finalBlocklet, componentDids: nonEntryComponentIds });
886
+ launcher.notifyBlockletStarted(finalBlocklet);
887
+
888
+ // 根据情况更新 route table
889
+ if (!['true', '1'].includes(process.env.ABT_NODE_DISABLE_BLUE_GREEN)) {
890
+ this.emit(BlockletEvents.blurOrGreenStarted, {
891
+ blocklet: finalBlocklet,
892
+ componentDids: inputComponentDids,
893
+ context,
894
+ });
895
+ }
896
+
897
+ return finalBlocklet;
898
+ }
899
+
871
900
  const doc1 = await states.blocklet.setBlockletStatus(did, BlockletStatus.starting, {
872
901
  componentDids,
873
902
  operator,
@@ -930,19 +959,25 @@ class DiskBlockletManager extends BaseBlockletManager {
930
959
  const finalBlocklet = await this.getBlocklet(did);
931
960
  resultBlocklet = finalBlocklet;
932
961
 
933
- await this.configSynchronizer.throttledSyncAppConfig(finalBlocklet);
962
+ await this.configSynchronizer.throttledSyncAppConfig(finalBlocklet, { wait: 200 });
934
963
  const componentsInfo = getComponentsInternalInfo(finalBlocklet);
935
964
  this.emit(BlockletInternalEvents.componentUpdated, {
936
965
  appDid: blocklet.appDid,
937
966
  components: componentsInfo,
938
967
  });
968
+
969
+ const allStartedComponentDids = uniq([
970
+ ...(componentDids || []),
971
+ ...nonEntryComponentIds,
972
+ ...startedBlockletDids.map((x) => x.did),
973
+ ]);
939
974
  this.emit(BlockletInternalEvents.componentStarted, {
940
975
  appDid: blocklet.appDid,
941
- components: (componentDids || []).map((x) => ({ did: x })),
976
+ components: allStartedComponentDids.map((x) => ({ did: x })),
942
977
  });
943
978
 
944
979
  this.emit(BlockletEvents.statusChange, finalBlocklet);
945
- this.emit(BlockletEvents.started, { ...finalBlocklet, componentDids });
980
+ this.emit(BlockletEvents.started, { ...finalBlocklet, componentDids: allStartedComponentDids });
946
981
 
947
982
  launcher.notifyBlockletStarted(finalBlocklet);
948
983
  }