export interface Grafter { (effect: Effect): Effect } /** * Transplants specified effects so that when those effects fork other * effects, the forked effects will be governed by the scope of the fiber that * executes this effect. * * This can be used to "graft" deep grandchildren onto a higher-level scope, * effectively extending their lifespans into the parent scope. * * @tsplus static effect/core/io/Effect.Ops transplant */ export function transplant( f: (grafter: Grafter) => Effect ): Effect { return Effect.withFiberRuntime((state) => { const scopeOverride = state.getFiberRef(FiberRef.forkScopeOverride) const scope = scopeOverride.getOrElse(state.scope) return f(FiberRef.forkScopeOverride.locally(Maybe.some(scope))) }) }