@pmate/chat-sdk 0.13.0-profile.2 → 0.13.0-profile.3
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.
|
@@ -28,6 +28,7 @@ export declare class ProfileCoordinator {
|
|
|
28
28
|
private closed;
|
|
29
29
|
private needsOwner;
|
|
30
30
|
private starting?;
|
|
31
|
+
private startupRetry?;
|
|
31
32
|
get identity(): import("./inboxStore.js").InboxScope;
|
|
32
33
|
get memory(): import("./profileMemoryStore.js").ProfileMemoryStore;
|
|
33
34
|
submit(operation: ProfileOperation, immediate?: boolean): Promise<void>;
|
|
@@ -13,6 +13,7 @@ export class ProfileCoordinator {
|
|
|
13
13
|
closed = false;
|
|
14
14
|
needsOwner = false;
|
|
15
15
|
starting;
|
|
16
|
+
startupRetry;
|
|
16
17
|
get identity() { return this.options.configuration.identity; }
|
|
17
18
|
get memory() { return this.replica.memory; }
|
|
18
19
|
submit(operation, immediate = false) { return this.replica.submit(operation, immediate); }
|
|
@@ -54,8 +55,27 @@ export class ProfileCoordinator {
|
|
|
54
55
|
return task;
|
|
55
56
|
}
|
|
56
57
|
async initialize() {
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
for (;;) {
|
|
59
|
+
if (this.closed)
|
|
60
|
+
throw Error("PROFILE_COORDINATOR_CLOSED");
|
|
61
|
+
try {
|
|
62
|
+
await this.acquire();
|
|
63
|
+
await this.replica.start(false);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (this.closed)
|
|
68
|
+
throw Error("PROFILE_COORDINATOR_CLOSED");
|
|
69
|
+
if (!["PROFILE_OWNER_TIMEOUT", "PROFILE_OWNER_UNAVAILABLE", "PROFILE_WORKER_TIMEOUT"].includes(error?.message))
|
|
70
|
+
throw error;
|
|
71
|
+
this.report(error);
|
|
72
|
+
this.needsOwner = true;
|
|
73
|
+
await new Promise(resolve => {
|
|
74
|
+
const timer = setTimeout(() => { this.startupRetry = undefined; resolve(); }, this.options.retryMs ?? 10000);
|
|
75
|
+
this.startupRetry = { timer, resolve };
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
59
79
|
if (!this.timer)
|
|
60
80
|
this.timer = setInterval(() => {
|
|
61
81
|
void this.replica.check().catch(error => {
|
|
@@ -123,6 +143,11 @@ export class ProfileCoordinator {
|
|
|
123
143
|
async close() {
|
|
124
144
|
this.closed = true;
|
|
125
145
|
clearInterval(this.timer);
|
|
146
|
+
if (this.startupRetry) {
|
|
147
|
+
clearTimeout(this.startupRetry.timer);
|
|
148
|
+
this.startupRetry.resolve();
|
|
149
|
+
this.startupRetry = undefined;
|
|
150
|
+
}
|
|
126
151
|
this.replica.close();
|
|
127
152
|
this.channel.removeEventListener("message", this.workerMessage);
|
|
128
153
|
this.channel.close();
|
package/package.json
CHANGED