I’m trying to update my Node.js code to use the callbacks in order to make sure everything is done in the right order, but doing so is causing a stack overflow exception in Node.js, which terminates the process.
The below program should run forever (and I would not expect to see many errors). However, I see errors quite frequently and after a few thousand loops, Node.js crashes with a stack exhaustion.
var mBlinkStick = require("blinkstick"),
oBlinkStick = mBlinkStick.findFirst();
function fSetMode() {
oBlinkStick.setMode(2, function (oError) {
console.log("mode set:", oError);
fSetMode();
});
};
fSetMode();
By adding a timeout, the stack exhaustion is avoided. I still see errors, but the program can run forever.
var mBlinkStick = require("blinkstick"),
mColor = require("mColor"),
oBlinkStick = mBlinkStick.findFirst();
function fSetMode() {
oBlinkStick.setMode(2, function (oError) {
console.log("mode set:", oError);
setTimeout(fSetMode, 0);
});
};
fSetMode();
The errors are not related to this issue, but might be interesting to look into at some point.
I assume this crashes because you are calling the callback from your addon immediately, which would cause a loop, rather than queuing the call to be made after your code is finished. I’m not sure how to resolve this, as I’ve not dealt with callbacks in addon code myself yet.