This commit is contained in:
Raven Scott
2026-04-22 19:48:28 -04:00
parent c8e6b3b6d4
commit 45a8a3fde6
@@ -489,15 +489,20 @@ async function stopManagedInstance(ctx, id) {
logLine(ctx, `managed: stopped ${id}`)
}
/** Yield one tick so `bare-os-www` (and other writers) can finish persisting `~/.holesail/state.json`. */
function yieldForStateCoalescence() {
return new Promise((resolve) => {
if (typeof globalThis.setImmediate === 'function') globalThis.setImmediate(resolve)
else queueMicrotask(resolve)
})
}
/**
* Start every enabled connection from a fresh read of disk (used for initial start + reconcile pass).
* @param {Record<string, unknown>} ctx
* @param {Record<string, string | undefined>} env
*/
export async function bareHolesailManagedStartService(ctx, env) {
if (managedServiceRunning) return
managedServiceRunning = true
async function startManagedConnectionsFromDisk(ctx, env) {
const { state } = await bareHolesailManagedReadState(ctx, env)
const idsSorted = Object.keys(state.connections).sort()
for (const id of idsSorted) {
@@ -518,6 +523,20 @@ export async function bareHolesailManagedStartService(ctx, env) {
}
}
}
}
/**
* @param {Record<string, unknown>} ctx
* @param {Record<string, string | undefined>} env
*/
export async function bareHolesailManagedStartService(ctx, env) {
if (managedServiceRunning) return
managedServiceRunning = true
await startManagedConnectionsFromDisk(ctx, env)
await yieldForStateCoalescence()
await startManagedConnectionsFromDisk(ctx, env)
managedHookUnsubs.push(
ctx.bareOsRegisterSuspendHook(async () => {