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

Function loadSharedHandle

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

Source from the content-addressed store, hash-verified

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