| 608 | } |
| 609 | |
| 610 | const runImpl = <A, E, R, XE extends E, XA extends A>( |
| 611 | self: FiberHandle<A, E>, |
| 612 | effect: Effect.Effect<XA, XE, R>, |
| 613 | options?: { |
| 614 | readonly onlyIfMissing?: boolean | undefined |
| 615 | } |
| 616 | ): Effect.Effect<Fiber.Fiber<XA, XE>, never, R> => |
| 617 | Effect.withFiber((parent) => { |
| 618 | if (self.state._tag === "Closed") { |
| 619 | return Effect.interrupt |
| 620 | } else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) { |
| 621 | return Effect.sync(constInterruptedFiber) |
| 622 | } |
| 623 | const fiber = Effect.runForkWith(parent.context as Context<R>)(effect) |
| 624 | setUnsafe(self, fiber, options) |
| 625 | return Effect.succeed(fiber) |
| 626 | }) |
| 627 | |
| 628 | /** |
| 629 | * Captures the current runtime and returns a function for forking effects into |