阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js MessagePort port.postMessage

      Node.js MessagePort port.postMessage(value[, transferList])

      新增于: v10.5.0

      • value < any>
      • transferList <Object[]>

      Sends a JavaScript value to the receiving side of this channel. value will be transferred in a way which is compatible with the HTML structured clone algorithm. In particular, it may contain circular references and objects like typed arrays that the JSON API is not able to stringify.

      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 工作线程,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录