MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / reloadIfSafe

Function reloadIfSafe

desktop/runtime/settings-refresh.ts:109–155  ·  view source on GitHub ↗
(
    sessionPath: string,
    options: { useMutationLock?: boolean | undefined } = {},
  )

Source from the content-addressed store, hash-verified

107 }
108
109 async function reloadIfSafe(
110 sessionPath: string,
111 options: { useMutationLock?: boolean | undefined } = {},
112 ): Promise<boolean> {
113 const runtimeKey = getPersistedSessionPath(sessionPath)
114 if (!(runtimeKey && staleGenerations.has(runtimeKey))) {
115 return false
116 }
117
118 if (options.useMutationLock ?? true) {
119 return await withRuntimeMutationLock(runtimeKey, () =>
120 reloadIfSafe(runtimeKey, { useMutationLock: false }),
121 )
122 }
123
124 const runtimePromise = getCachedRuntimeForSessionPath(runtimeKey)
125 if (!runtimePromise) {
126 staleGenerations.delete(runtimeKey)
127 return false
128 }
129
130 const runtime = await runtimePromise
131 try {
132 const { reloaded, reloadedGeneration } = await reloadRuntimeUntilStable({
133 isRuntimeBusy: isRuntimeBusyOption,
134 reloadRuntimeSettings,
135 runtime,
136 runtimeKey,
137 staleGenerations,
138 })
139
140 if (reloaded) {
141 await publishReloadedComposer({
142 buildComposerState,
143 publishComposerUpdate,
144 reloadedGeneration,
145 runtime,
146 runtimeKey,
147 staleGenerations,
148 })
149 }
150 return reloaded
151 } catch {
152 // Keep the stale mark; the next safe point retries silently.
153 return false
154 }
155 }
156
157 function markStale(sessionPath: string | null | undefined) {
158 const runtimeKey = getPersistedSessionPath(sessionPath ?? null)

Callers 3

markStaleFunction · 0.85
markStaleForProjectFunction · 0.85
markStaleForSettingsCwdFunction · 0.85

Calls 5

getPersistedSessionPathFunction · 0.90
reloadRuntimeUntilStableFunction · 0.85
publishReloadedComposerFunction · 0.85
withRuntimeMutationLockFunction · 0.50

Tested by

no test coverage detected