MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / loadSharedHandle

Function loadSharedHandle

apps/local/src/executor.ts:276–308  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

274let sharedHandleLifecycle: Promise<void> = Promise.resolve();
275
276const loadSharedHandle = (): Promise<ExecutorHandle> => {
277 if (sharedHandlePromise) {
278 return sharedHandlePromise;
279 }
280
281 // Capture the lifecycle tail at call time so creation stays ordered behind
282 // in-flight dispose
283 const lifecycle = sharedHandleLifecycle;
284
285 // Identity token the heal closure compares against. Using a `let` declared
286 // up front avoids any reference-before-init ambiguity in the closure.
287 let slot: Promise<ExecutorHandle>;
288
289 const acquire = Effect.tryPromise({
290 try: () => lifecycle.then(() => createExecutorHandle()),
291 catch: (cause) => new SharedHandleCreateError({ cause }),
292 }).pipe(
293 // Self-heal: a failed creation must not poison the memo. Clear the slot on
294 // any non-success outcome so the next getExecutor() retries, but only if a
295 // dispose/reload hasn't already swapped in a newer promise (identity guard).
296 Effect.onError(() =>
297 Effect.sync(() => {
298 if (sharedHandlePromise === slot) {
299 sharedHandlePromise = null;
300 }
301 }),
302 ),
303 );
304
305 slot = Effect.runPromise(acquire);
306 sharedHandlePromise = slot;
307 return slot;
308};
309
310export const getExecutor = () => loadSharedHandle().then((handle) => handle.executor);
311export const getExecutorBundle = () => loadSharedHandle();

Callers 2

getExecutorFunction · 0.85
getExecutorBundleFunction · 0.85

Calls 2

createExecutorHandleFunction · 0.85
syncMethod · 0.65

Tested by

no test coverage detected