homebridge-pioneer-avr-2025
Version:
A Pioneer AVR plugin for homebridge. This plugin is designed for Pioneer models that use Telnet Commands (e.g., VSX-922). It may not be compatible with newer models (e.g., VSX-LX304).
39 lines • 1.17 kB
JavaScript
;
// src/exitHandler.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.addExitHandler = addExitHandler;
const handlers = [];
/**
* Adds an exit handler function with an optional context.
* @param handler - The handler function to execute on exit.
* @param context - The context to bind the handler function to.
*/
function addExitHandler(handler, context) {
handlers.push({ handler, context });
}
/**
* Runs all registered exit handlers in their respective contexts.
*/
let runHandlersCalled = false;
function runHandlers() {
if (runHandlersCalled) {
return;
}
runHandlersCalled = true;
handlers.forEach(({ handler, context }) => {
try {
handler.call(context);
}
catch (e) {
console.error('Error executing exit handler:', e);
}
});
}
// Keep the process alive by listening to stdin
process.stdin.resume();
// Bind the exit handler to various termination signals
process.on('exit', runHandlers);
process.on('SIGINT', runHandlers);
process.on('SIGUSR1', runHandlers);
process.on('SIGUSR2', runHandlers);
//# sourceMappingURL=exitHandler.js.map