@cydm/happy-elves 0.1.0-beta.241 → 0.1.0-beta.245
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/apps/cli/package.json
CHANGED
package/apps/daemon/package.json
CHANGED
package/package.json
CHANGED
|
@@ -101,11 +101,14 @@ export async function sendCommand(context, command, waitForDone = false, timeout
|
|
|
101
101
|
const targetTurnId = "turnId" in command ? command.turnId : undefined;
|
|
102
102
|
return await new Promise((resolve, reject) => {
|
|
103
103
|
let settled = false;
|
|
104
|
+
let retainedPoller;
|
|
104
105
|
const finish = (result) => {
|
|
105
106
|
if (settled)
|
|
106
107
|
return;
|
|
107
108
|
settled = true;
|
|
108
109
|
globalThis.clearTimeout(timer);
|
|
110
|
+
if (retainedPoller)
|
|
111
|
+
globalThis.clearInterval(retainedPoller);
|
|
109
112
|
ws.close();
|
|
110
113
|
resolve(result);
|
|
111
114
|
};
|
|
@@ -114,6 +117,8 @@ export async function sendCommand(context, command, waitForDone = false, timeout
|
|
|
114
117
|
return;
|
|
115
118
|
settled = true;
|
|
116
119
|
globalThis.clearTimeout(timer);
|
|
120
|
+
if (retainedPoller)
|
|
121
|
+
globalThis.clearInterval(retainedPoller);
|
|
117
122
|
ws.close();
|
|
118
123
|
reject(error);
|
|
119
124
|
};
|
|
@@ -125,7 +130,11 @@ export async function sendCommand(context, command, waitForDone = false, timeout
|
|
|
125
130
|
dispatch: ackedDispatch,
|
|
126
131
|
events,
|
|
127
132
|
});
|
|
133
|
+
let retainedLookupInFlight = false;
|
|
128
134
|
const resolveFromRetainedTurnIfDone = (sessionId, turnId) => {
|
|
135
|
+
if (retainedLookupInFlight)
|
|
136
|
+
return;
|
|
137
|
+
retainedLookupInFlight = true;
|
|
129
138
|
void context.sessionEvents(sessionId, { limit: 1000 })
|
|
130
139
|
.then(({ events: retainedEvents }) => retainedEvents.filter((event) => event.turnId === turnId))
|
|
131
140
|
.then(async (turnEvents) => {
|
|
@@ -142,7 +151,19 @@ export async function sendCommand(context, command, waitForDone = false, timeout
|
|
|
142
151
|
events.sort((left, right) => left.id - right.id);
|
|
143
152
|
finish(commandResultFromAck());
|
|
144
153
|
})
|
|
145
|
-
.catch(() => { })
|
|
154
|
+
.catch(() => { })
|
|
155
|
+
.finally(() => {
|
|
156
|
+
retainedLookupInFlight = false;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
const startRetainedTurnPoller = (sessionId, turnId) => {
|
|
160
|
+
if (retainedPoller)
|
|
161
|
+
return;
|
|
162
|
+
resolveFromRetainedTurnIfDone(sessionId, turnId);
|
|
163
|
+
retainedPoller = globalThis.setInterval(() => {
|
|
164
|
+
if (!settled)
|
|
165
|
+
resolveFromRetainedTurnIfDone(sessionId, turnId);
|
|
166
|
+
}, 2_000);
|
|
146
167
|
};
|
|
147
168
|
const timer = globalThis.setTimeout(() => {
|
|
148
169
|
fail(new ControllerClientError("Timed out waiting for command result", "COMMAND_TIMEOUT", {
|
|
@@ -182,7 +203,7 @@ export async function sendCommand(context, command, waitForDone = false, timeout
|
|
|
182
203
|
finish(commandResultFromAck());
|
|
183
204
|
}
|
|
184
205
|
else if (targetSessionId && targetTurnId) {
|
|
185
|
-
|
|
206
|
+
startRetainedTurnPoller(targetSessionId, targetTurnId);
|
|
186
207
|
}
|
|
187
208
|
return;
|
|
188
209
|
}
|