@ricsam/isolate-daemon 0.1.20 → 0.1.21
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/cjs/connection.cjs
CHANGED
|
@@ -47,6 +47,7 @@ var import_isolate_protocol = require("@ricsam/isolate-protocol");
|
|
|
47
47
|
var import_callback_fs_handler = require("./callback-fs-handler.cjs");
|
|
48
48
|
var import_isolate_runtime = require("@ricsam/isolate-runtime");
|
|
49
49
|
var LINKER_CONFLICT_ERROR = "Module is currently being linked by another linker";
|
|
50
|
+
var NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
|
|
50
51
|
function getErrorText(error) {
|
|
51
52
|
if (error instanceof Error) {
|
|
52
53
|
const cause = error.cause;
|
|
@@ -1480,16 +1481,36 @@ function handleCallbackStreamStart(message, connection) {
|
|
|
1480
1481
|
return Promise.resolve();
|
|
1481
1482
|
}
|
|
1482
1483
|
});
|
|
1484
|
+
const cancelStream = () => {
|
|
1485
|
+
connection.callbackStreamReceivers.delete(message.streamId);
|
|
1486
|
+
sendMessage(connection.socket, {
|
|
1487
|
+
type: import_isolate_protocol.MessageType.CALLBACK_STREAM_CANCEL,
|
|
1488
|
+
streamId: message.streamId
|
|
1489
|
+
});
|
|
1490
|
+
};
|
|
1483
1491
|
connection.callbackStreamReceivers.set(message.streamId, receiver);
|
|
1484
1492
|
const pending = connection.pendingCallbacks.get(message.requestId);
|
|
1485
|
-
if (pending) {
|
|
1486
|
-
|
|
1487
|
-
|
|
1493
|
+
if (!pending) {
|
|
1494
|
+
cancelStream();
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
try {
|
|
1498
|
+
const body = NULL_BODY_STATUSES.has(message.metadata.status) ? null : readableStream;
|
|
1499
|
+
const response = new Response(body, {
|
|
1488
1500
|
status: message.metadata.status,
|
|
1489
1501
|
statusText: message.metadata.statusText,
|
|
1490
1502
|
headers: message.metadata.headers
|
|
1491
1503
|
});
|
|
1504
|
+
connection.pendingCallbacks.delete(message.requestId);
|
|
1492
1505
|
pending.resolve({ __streamingResponse: true, response });
|
|
1506
|
+
if (body === null) {
|
|
1507
|
+
cancelStream();
|
|
1508
|
+
}
|
|
1509
|
+
} catch (err) {
|
|
1510
|
+
connection.pendingCallbacks.delete(message.requestId);
|
|
1511
|
+
cancelStream();
|
|
1512
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
1513
|
+
pending.reject(error);
|
|
1493
1514
|
}
|
|
1494
1515
|
}
|
|
1495
1516
|
function handleCallbackStreamChunk(message, connection) {
|
|
@@ -1752,4 +1773,4 @@ async function handleClearCollectedData(message, connection, state) {
|
|
|
1752
1773
|
}
|
|
1753
1774
|
}
|
|
1754
1775
|
|
|
1755
|
-
//# debugId=
|
|
1776
|
+
//# debugId=CCDD5E4DA24900F364756E2164756E21
|