| 27 | } |
| 28 | |
| 29 | async function reloadRuntimeUntilStable(input: { |
| 30 | isRuntimeBusy: (runtime: PiRuntime) => boolean |
| 31 | reloadRuntimeSettings: (runtimeKey: string, runtime: PiRuntime) => Promise<boolean> |
| 32 | runtime: PiRuntime |
| 33 | runtimeKey: string |
| 34 | staleGenerations: Map<string, number> |
| 35 | }) { |
| 36 | let reloaded = false |
| 37 | let reloadedGeneration: number | null = null |
| 38 | while (!input.isRuntimeBusy(input.runtime)) { |
| 39 | const generation = input.staleGenerations.get(input.runtimeKey) |
| 40 | if (generation === undefined) break |
| 41 | const didReload = await input.reloadRuntimeSettings(input.runtimeKey, input.runtime) |
| 42 | if (!didReload) break |
| 43 | reloaded = true |
| 44 | reloadedGeneration = generation |
| 45 | if (input.staleGenerations.get(input.runtimeKey) === generation) break |
| 46 | } |
| 47 | return { reloaded, reloadedGeneration } |
| 48 | } |
| 49 | |
| 50 | async function publishReloadedComposer(input: { |
| 51 | buildComposerState: (runtime: PiRuntime) => Promise<ComposerState> |