Mark an object as not transferable. If object occurs in the transfer list of a [port.postMessage()][] call, it will be ignored.

    In particular, this makes sense for objects that can be cloned, rather than transferred, and which are used by other objects on the sending side. For example, Node.js marks the ArrayBuffers it uses for its [Buffer pool][Buffer.allocUnsafe()] with this.

    This operation cannot be undone.

    1. const { MessageChannel, markAsUntransferable } = require('worker_threads');
    2. const pooledBuffer = new ArrayBuffer(8);
    3. const typedArray1 = new Uint8Array(pooledBuffer);
    4. const typedArray2 = new Float64Array(pooledBuffer);
    5. markAsUntransferable(pooledBuffer);
    6. const { port1 } = new MessageChannel();
    7. port1.postMessage(typedArray1, [ typedArray1.buffer ]);
    8. // The following line prints the contents of typedArray1 -- it still owns
    9. // its memory and has been cloned, not transferred. Without
    10. // `markAsUntransferable()`, this would print an empty Uint8Array.
    11. // typedArray2 is intact as well.
    12. console.log(typedArray1);
    13. console.log(typedArray2);

    There is no equivalent to this API in browsers.