Is it safe to pass js callback to a ffi function which calls it in another thread?

删除回忆录丶 提交于 2019-12-04 05:13:36

Hacked together a quick demo to test this out: https://github.com/madadam/rust_ffi_async_demo. (using rust, not C for the native part, but that should be equivalent as rust can build to normal shared library).

So, after running the demo, I would answer my own questions like this:

  • Yes, it seems to be valid and safe
  • The js callback gets executed in the main thread
  • Node-FFI seems to handle the synchronization by pushing the js callback to a queue which gets popped on the main thread.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!