Node.js MessagePort port.postMessage
Node.js MessagePort port.postMessage(value[, transferList])
- value < any>
- transferList <Object>
transferList may be a list of ArrayBuffer and MessagePort objects. After transferring, they will not be usable on the sending side of the channel anymore (even if they are not contained in value). Unlike with child processes, transferring handles such as network sockets is currently not supported.
If value contains SharedArrayBuffer instances, those will be accessible from either thread. They cannot be listed in transferList.
value may still contain ArrayBuffer instances that are not in transferList; in that case, the underlying memory is copied rather than moved.
Because the object cloning uses the structured clone algorithm, non-enumerable properties, property accessors, and object prototypes are not preserved. In particular, Buffer objects will be read as plain Uint8Arrays on the receiving side.
The message object will be cloned immediately, and can be modified after posting without having side effects.
For more information on the serialization and deserialization mechanisms behind this API, see the serialization API of the v8 module.
更多内容请参考：Node.js worker_threads 工作线程，或者通过 点击对应菜单 进行查看；