OiO.lk Blog javascript Reading from a ReadableStreamDefaultReader of transferred WebTransportReceiveStream (ReadableStream) to worker leads to DataCloneError
javascript

Reading from a ReadableStreamDefaultReader of transferred WebTransportReceiveStream (ReadableStream) to worker leads to DataCloneError


After trying a similar example to what is found at whatwg, both Firefox and Chrome fail at reader.read() with a DataCloneError: A ReadableStream could not be cloned because it was not transferred. on the worker, but the worker has successfully received the transferred ReadableStream. Is this just that the browsers I’m using do not support this functionality or am I doing something wrong?

In theory a WebTransportReceiveStream is a transferable object, I have the following reduced files for my code.

worker.js:

onmessage = async (evt) => {
  const rs = evt.data;
  const reader = rs.getReader();
  const {value, done} = await reader.read();
  console.error(value);
};

main.js:

async function setup() {
  const t = new WebTransport('https://localhost:4443');
  await t.ready
  const uds = t.incomingUnidirectionalStreams;
  const w = new Worker('worker.js');
  w.postMessage(uds, [uds]);
}

await setup();

index.html:

<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="main.js"></script>
  </head>
  <body>
  </body>
</html>



You need to sign in to view this answers

Exit mobile version