I am writing my own node module in C ++, which will be a binding for the C library.
Some of the objects in this library should be used by only one thread . This means that if I use uv_queue_work , I canโt make sure that they are used only by the same thread, since, as far as I know, libuv uses the thread pool, and I could not find out how to tell which thread to use for this kind works.
Here are some ideas for the situation, but I'm not sure if this is the right approach.
- Just make all methods synchronous - this, unfortunately, will surpass the goals and concepts of node, so I would rather not
- Create your own thread and execute my code on this - this will hit the target of the libuv thread pool and will require more work.
- Tell libuv to somehow perform the operations of the same object in the same thread in the thread pool - I did not find a way in the documentation to do this
What is the recommended course for this type of Node.js module?
source share