| 476 | } |
| 477 | |
| 478 | const runImpl = <K, A, E, R, XE extends E, XA extends A>( |
| 479 | self: FiberMap<K, A, E>, |
| 480 | key: K, |
| 481 | effect: Effect.Effect<XA, XE, R>, |
| 482 | options?: { |
| 483 | readonly onlyIfMissing?: boolean |
| 484 | readonly propagateInterruption?: boolean | undefined |
| 485 | } |
| 486 | ) => |
| 487 | Effect.withFiberRuntime((parent) => { |
| 488 | if (self.state._tag === "Closed") { |
| 489 | return Effect.interrupt |
| 490 | } else if (options?.onlyIfMissing === true && unsafeHas(self, key)) { |
| 491 | return Effect.sync(constInterruptedFiber) |
| 492 | } |
| 493 | const runtime = Runtime.make<R>({ |
| 494 | context: parent.currentContext as any, |
| 495 | fiberRefs: parent.getFiberRefs(), |
| 496 | runtimeFlags: Runtime.defaultRuntime.runtimeFlags |
| 497 | }) |
| 498 | const fiber = Runtime.runFork(runtime)(effect) |
| 499 | unsafeSet(self, key, fiber, { ...options, interruptAs: parent.id() }) |
| 500 | return Effect.succeed(fiber) |
| 501 | }) |
| 502 | |
| 503 | /** |
| 504 | * Capture a Runtime and use it to fork Effect's, adding the forked fibers to the FiberMap. |