| 369 | } |
| 370 | |
| 371 | const runImpl = <A, E, R, XE extends E, XA extends A>( |
| 372 | self: FiberHandle<A, E>, |
| 373 | effect: Effect.Effect<XA, XE, R>, |
| 374 | options?: { |
| 375 | readonly onlyIfMissing?: boolean |
| 376 | readonly propagateInterruption?: boolean | undefined |
| 377 | } |
| 378 | ): Effect.Effect<Fiber.RuntimeFiber<XA, XE>, never, R> => |
| 379 | Effect.withFiberRuntime((parent) => { |
| 380 | if (self.state._tag === "Closed") { |
| 381 | return Effect.interrupt |
| 382 | } else if (self.state.fiber !== undefined && options?.onlyIfMissing === true) { |
| 383 | return Effect.sync(constInterruptedFiber) |
| 384 | } |
| 385 | const runtime = Runtime.make<R>({ |
| 386 | context: parent.currentContext as any, |
| 387 | fiberRefs: parent.getFiberRefs(), |
| 388 | runtimeFlags: Runtime.defaultRuntime.runtimeFlags |
| 389 | }) |
| 390 | const fiber = Runtime.runFork(runtime)(effect) |
| 391 | unsafeSet(self, fiber, { ...options, interruptAs: parent.id() }) |
| 392 | return Effect.succeed(fiber) |
| 393 | }) |
| 394 | |
| 395 | /** |
| 396 | * Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberHandle. |