openzca 0.1.18 → 0.1.20
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/dist/cli.js +33 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -831,6 +831,36 @@ async function withTimeout(task, timeoutMs, message) {
|
|
|
831
831
|
if (timeoutId) clearTimeout(timeoutId);
|
|
832
832
|
}
|
|
833
833
|
}
|
|
834
|
+
async function stopUploadListenerSafely(api, command, waitClosedMs = 1500) {
|
|
835
|
+
await new Promise((resolve) => {
|
|
836
|
+
let settled = false;
|
|
837
|
+
let timeoutId;
|
|
838
|
+
const finish = () => {
|
|
839
|
+
if (settled) return;
|
|
840
|
+
settled = true;
|
|
841
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
842
|
+
api.listener.off("closed", onClosed);
|
|
843
|
+
resolve();
|
|
844
|
+
};
|
|
845
|
+
const onClosed = () => {
|
|
846
|
+
finish();
|
|
847
|
+
};
|
|
848
|
+
api.listener.on("closed", onClosed);
|
|
849
|
+
timeoutId = setTimeout(finish, waitClosedMs);
|
|
850
|
+
try {
|
|
851
|
+
const internalWs = api.listener.ws;
|
|
852
|
+
if (internalWs && typeof internalWs.close === "function") {
|
|
853
|
+
internalWs.close(1e3);
|
|
854
|
+
writeDebugLine("msg.upload.listener.stop.ws_close", void 0, command);
|
|
855
|
+
} else {
|
|
856
|
+
api.listener.stop();
|
|
857
|
+
writeDebugLine("msg.upload.listener.stop", void 0, command);
|
|
858
|
+
}
|
|
859
|
+
} catch {
|
|
860
|
+
finish();
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
}
|
|
834
864
|
async function withUploadListener(api, command, task) {
|
|
835
865
|
const connectTimeoutMs = parsePositiveIntFromEnv(
|
|
836
866
|
"OPENZCA_UPLOAD_LISTENER_CONNECT_TIMEOUT_MS",
|
|
@@ -928,15 +958,11 @@ async function withUploadListener(api, command, task) {
|
|
|
928
958
|
`Timed out waiting ${uploadTimeoutMs}ms for file upload completion.`
|
|
929
959
|
);
|
|
930
960
|
} finally {
|
|
931
|
-
api.listener.off("error", sinkError);
|
|
932
|
-
api.listener.off("closed", sinkClosed);
|
|
933
961
|
if (startedHere) {
|
|
934
|
-
|
|
935
|
-
api.listener.stop();
|
|
936
|
-
writeDebugLine("msg.upload.listener.stop", void 0, command);
|
|
937
|
-
} catch {
|
|
938
|
-
}
|
|
962
|
+
await stopUploadListenerSafely(api, command);
|
|
939
963
|
}
|
|
964
|
+
api.listener.off("error", sinkError);
|
|
965
|
+
api.listener.off("closed", sinkClosed);
|
|
940
966
|
}
|
|
941
967
|
}
|
|
942
968
|
async function fetchRecentMessagesViaListener(api, threadId, threadType, count) {
|