It appears the callbacks are called from inside a try … catch block, and any exception they throw will result in more calls to the callback.
var mBlinkStick = require("blinkstick"),
oBlinkStick = mBlinkStick.findFirst();
oBlinkStick.setMode(2, function (oError) {
if (oError) {
console.log("callback with error:", oError);
} else {
console.log("callback without error");
throw new Error("This should not cause another callback");
}
});
Expected output:
H:\dev\node\pWinStatusBlinkStick>test2.js
callback without error
H:\dev\node\pWinStatusBlinkStick\test2.js:9
throw new Error("This should not cause another callback");
^
Error: This should not cause another callback
at ...
Actual output:
H:\dev\node\pWinStatusBlinkStick>test2.js
callback without error
callback without error
callback with error: [Error: This should not cause another callback]
I believe you can resolve this in your code by wrapping the callbacks in a setTimeout(…, 0), by replacing this:
fCallback(arg0, arg1, ...);
With this:
setTimeout(function () {
fCallback(arg0, arg1, ...);
}, 0);
I’ll look into submitting another pull request for this issue tomorrow. Doing this should also resolve the stack exhaustion bug I reported earlier today.