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

Method constructor

packages/platform/node-shared/src/NodeStream.ts:518–548  ·  view source on GitHub ↗
(
    context: Context.Context<R>,
    stream: Stream.Stream<Uint8Array | string, E, R>
  )

Source from the content-addressed store, hash-verified

516 private fiber: Fiber.Fiber<void, E> | undefined = undefined
517
518 constructor(
519 context: Context.Context<R>,
520 stream: Stream.Stream<Uint8Array | string, E, R>
521 ) {
522 super({})
523 this.readLatch = Latch.makeUnsafe(false)
524 this.fiber = Stream.runForEachArray(stream, (chunk) =>
525 this.readLatch.whenOpen(Effect.sync(() => {
526 this.readLatch.closeUnsafe()
527 for (let i = 0; i < chunk.length; i++) {
528 const item = chunk[i]
529 if (typeof item === "string") {
530 this.push(item, "utf8")
531 } else {
532 this.push(item)
533 }
534 }
535 }))).pipe(
536 this.readLatch.whenOpen,
537 Effect.provideContext(context),
538 Effect.runFork
539 )
540 this.fiber.addObserver((exit) => {
541 this.fiber = undefined
542 if (Exit.isSuccess(exit)) {
543 this.push(null)
544 } else {
545 this.destroy(Cause.squash(exit.cause) as any)
546 }
547 })
548 }
549
550 override _read(_size: number): void {
551 this.readLatch.openUnsafe()

Callers

nothing calls this directly

Calls 7

whenOpenMethod · 0.80
addObserverMethod · 0.80
pipeMethod · 0.65
closeUnsafeMethod · 0.65
pushMethod · 0.65
syncMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected