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

Function loadSharedHandle

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

Source from the content-addressed store, hash-verified

293let sharedHandleLifecycle: Promise<void> = Promise.resolve();
294
295const loadSharedHandle = (): Promise<ExecutorHandle> => {
296 if (sharedHandlePromise) {
297 return sharedHandlePromise;
298 }
299
300 // Capture the lifecycle tail at call time so creation stays ordered behind
301 // in-flight dispose
302 const lifecycle = sharedHandleLifecycle;
303
304 // Identity token the heal closure compares against. Using a `let` declared
305 // up front avoids any reference-before-init ambiguity in the closure.
306 let slot: Promise<ExecutorHandle>;
307
308 const acquire = Effect.tryPromise({
309 try: () => lifecycle.then(() => createExecutorHandle()),
310 catch: (cause) => new SharedHandleCreateError({ cause }),
311 }).pipe(
312 // Self-heal: a failed creation must not poison the memo. Clear the slot on
313 // any non-success outcome so the next getExecutor() retries, but only if a
314 // dispose/reload hasn't already swapped in a newer promise (identity guard).
315 Effect.onError(() =>
316 Effect.sync(() => {
317 if (sharedHandlePromise === slot) {
318 sharedHandlePromise = null;
319 }
320 }),
321 ),
322 );
323
324 slot = Effect.runPromise(acquire);
325 sharedHandlePromise = slot;
326 return slot;
327};
328
329export const getExecutor = () => loadSharedHandle().then((handle) => handle.executor);
330export 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