Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Addon Require multiple times new instace

How can I avoid cache with require('c++addon'). I have an addon but will like to have a new one every time.

e.g

for(...)
 addon[i] = require('addon'); // I want a new one everytime
 addon[i].somefunction(); //  

Thank you.

like image 467
lizet Avatar asked Jun 13 '26 08:06

lizet


1 Answers

You will have to refactor your addon module so it exposes a function to construct these instances, e.g.

const myAddon = require('addon');
objects = [myAddon.create(), myAddon.create(), myAddon.create()];
objects[0].somefunction();
like image 56
AKX Avatar answered Jun 16 '26 01:06

AKX