"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.requestRestart = requestRestart;
exports.restartNeeded = restartNeeded;
exports.resetRestartNeeded = resetRestartNeeded;
exports.subscribeToRestartRequests = subscribeToRestartRequests;
const index_ts_1 = require("../server/status/index.js");
let restartArrayBuffer;
let restartNeededArray;
let onRestartRequestedCallback = null;
function ensureInitialized() {
    if (!restartArrayBuffer) {
        restartArrayBuffer = index_ts_1.Status.primaryStore.getUserSharedBuffer('restart-needed', new ArrayBuffer(1), {
            callback: () => onRestartRequestedCallback?.(),
        });
        restartNeededArray = new Uint8Array(restartArrayBuffer);
    }
}
function requestRestart() {
    ensureInitialized();
    restartNeededArray[0] = 1;
    restartArrayBuffer.notify();
}
function restartNeeded() {
    ensureInitialized();
    return restartNeededArray[0] === 1;
}
function resetRestartNeeded() {
    ensureInitialized();
    restartNeededArray[0] = 0;
}
function subscribeToRestartRequests(callback) {
    ensureInitialized();
    if (onRestartRequestedCallback)
        throw new Error('A restart-request subscriber is already registered');
    onRestartRequestedCallback = callback;
}
//# sourceMappingURL=requestRestart.js.map