()
| 293 | let sharedHandleLifecycle: Promise<void> = Promise.resolve(); |
| 294 | |
| 295 | const 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 | |
| 329 | export const getExecutor = () => loadSharedHandle().then((handle) => handle.executor); |
| 330 | export const getExecutorBundle = () => loadSharedHandle(); |
no test coverage detected