dimanche 11 septembre 2016

Node.js addon singleton

I have a C++ addon for Node which I have to wrap into small js shim (library) and use it along with other modules in my project. The problem is, I have to maintain a single state for this addon (it's working with files, opening a lots of handles etc), so when I require it in one file and do some operations with it, I can be sure that when I will require it in another file it won't create all handles and execute all C++ constructing code again. How can I implement this? I thought about using a Singleton pattern in a shimming library, but I've read they don't play nice with module.export. Is it true? I'm using node 4.5+

Aucun commentaire:

Enregistrer un commentaire