@ricsam/isolate-client 0.1.17 → 0.1.18

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.
@@ -660,6 +660,8 @@ async function createRuntime(state, options = {}, namespaceId) {
660
660
  if (signal?.aborted) {
661
661
  throw new DOMException("The operation was aborted", "AbortError");
662
662
  }
663
+ const requestSignal = req.signal;
664
+ const requestSignalInitiallyAborted = requestSignal?.aborted ?? false;
663
665
  const reqId = state.nextRequestId++;
664
666
  const serialized = await serializeRequestWithStreaming(state, req);
665
667
  const { bodyStream, ...serializableRequest } = serialized;
@@ -686,6 +688,23 @@ async function createRuntime(state, options = {}, namespaceId) {
686
688
  };
687
689
  signal.addEventListener("abort", onAbort, { once: true });
688
690
  }
691
+ let onRequestAbort;
692
+ if (requestSignal && !requestSignalInitiallyAborted) {
693
+ onRequestAbort = () => {
694
+ const abortMessage = {
695
+ type: import_isolate_protocol.MessageType.DISPATCH_REQUEST_ABORT,
696
+ isolateId,
697
+ targetRequestId: reqId
698
+ };
699
+ if (state.connected) {
700
+ sendMessage(state.socket, abortMessage);
701
+ }
702
+ };
703
+ requestSignal.addEventListener("abort", onRequestAbort, { once: true });
704
+ if (requestSignal.aborted) {
705
+ onRequestAbort();
706
+ }
707
+ }
689
708
  try {
690
709
  if (serialized.bodyStreamId !== undefined && bodyStream) {
691
710
  const streamId = serialized.bodyStreamId;
@@ -701,6 +720,9 @@ async function createRuntime(state, options = {}, namespaceId) {
701
720
  if (signal && onAbort) {
702
721
  signal.removeEventListener("abort", onAbort);
703
722
  }
723
+ if (requestSignal && onRequestAbort) {
724
+ requestSignal.removeEventListener("abort", onRequestAbort);
725
+ }
704
726
  }
705
727
  },
706
728
  async getUpgradeRequest() {
@@ -1031,12 +1053,16 @@ function registerFetchCallback(state, callback) {
1031
1053
  state.callbacksNeedingRequestId.add(callbackId);
1032
1054
  state.callbacks.set(callbackId, async (serialized, requestId) => {
1033
1055
  const data = serialized;
1056
+ const signalController = new AbortController;
1057
+ if (data.signalAborted) {
1058
+ signalController.abort();
1059
+ }
1034
1060
  const init = {
1035
1061
  method: data.method,
1036
1062
  headers: data.headers,
1037
1063
  rawBody: data.body ?? null,
1038
1064
  body: data.body ?? null,
1039
- signal: new AbortController().signal
1065
+ signal: signalController.signal
1040
1066
  };
1041
1067
  const response = await callback(data.url, init);
1042
1068
  const contentLength = response.headers.get("content-length");
@@ -1407,7 +1433,8 @@ async function serializeRequestWithStreaming(state, request) {
1407
1433
  method: request.method,
1408
1434
  url: request.url,
1409
1435
  headers,
1410
- body
1436
+ body,
1437
+ signalAborted: request.signal?.aborted ?? false
1411
1438
  };
1412
1439
  if (bodyStreamId !== undefined) {
1413
1440
  result.bodyStreamId = bodyStreamId;
@@ -1664,4 +1691,4 @@ function handleClientWsClose(isolateId, payload, state) {
1664
1691
  }
1665
1692
  }
1666
1693
 
1667
- //# debugId=BB5A27475A32C8E264756E2164756E21
1694
+ //# debugId=E397D9CA05CE94DB64756E2164756E21