MCPcopy Create free account
hub / github.com/Effect-TS/effect / start

Function start

packages/effect/src/Stream.ts:11833–11862  ·  view source on GitHub ↗
(controller)

Source from the content-addressed store, hash-verified

11831
11832 return new ReadableStream<A>({
11833 start(controller) {
11834 fiber = Effect.runFork(Effect.provideContext(
11835 Channel.runForEach(
11836 Channel.transformPull(self.channel, (pull) => Effect.succeed(latch.whenOpen(pull))),
11837 (chunk) =>
11838 Effect.sync(() => {
11839 latch.closeUnsafe()
11840 for (let i = 0; i < chunk.length; i++) {
11841 controller.enqueue(chunk[i])
11842 }
11843 currentResolve!()
11844 currentResolve = undefined
11845 })
11846 ),
11847 context
11848 ))
11849 fiber.addObserver((exit) => {
11850 signal?.removeEventListener("abort", onAbort)
11851 if (cancelled) return
11852 if (exit._tag === "Failure" && signal?.aborted !== true) {
11853 controller.error(Cause.squash(exit.cause))
11854 } else {
11855 controller.close()
11856 }
11857 })
11858 if (signal !== undefined && fiber.pollUnsafe() === undefined) {
11859 if (signal.aborted) onAbort()
11860 else signal.addEventListener("abort", onAbort, { once: true })
11861 }
11862 },
11863 pull() {
11864 return new Promise<void>((resolve) => {
11865 currentResolve = resolve

Callers 2

Watch.test.tsFile · 0.50
requestFunction · 0.50

Calls 11

whenOpenMethod · 0.80
addObserverMethod · 0.80
pollUnsafeMethod · 0.80
onAbortFunction · 0.70
closeUnsafeMethod · 0.65
removeEventListenerMethod · 0.65
errorMethod · 0.65
closeMethod · 0.65
addEventListenerMethod · 0.65
succeedMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected