Concepts

Clone without a transfer list

Try the free JavaScript compiler

Clones an ordinary ArrayBuffer when no transfer is requested, leaving the original attached.

Formal Syntax & Structure

javascript syntaxjavascript
worker.postMessage(buffer)

Return Value

undefined

Clones an ordinary ArrayBuffer when no transfer is requested, leaving the original attached.

Working Example

Example Snippetjavascript
(async () => {const url=URL.createObjectURL(new Blob(['self.onmessage=e=>self.postMessage(e.data.byteLength);'],{type:"text/javascript"}));let w;try{w=new Worker(url);const b=new ArrayBuffer(3);const result=new Promise((ok,no)=>{w.onmessage=e=>ok(e.data);w.onerror=e=>no(new Error(e.message));});w.postMessage(b);console.log(b.byteLength,await result);}finally{w?.terminate();URL.revokeObjectURL(url);}})()
JavaScript Reference