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

Method constructor

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

Source from the content-addressed store, hash-verified

402 private fiber: Fiber.Fiber<void, E> | undefined = undefined
403
404 constructor(
405 context: Context.Context<R>,
406 stream: Stream.Stream<Uint8Array | string, E, R>
407 ) {
408 super({})
409 this.readLatch = Latch.makeUnsafe(false)
410 this.fiber = Stream.runForEachArray(stream, (chunk) =>
411 this.readLatch.whenOpen(Effect.sync(() => {
412 this.readLatch.closeUnsafe()
413 for (let i = 0; i < chunk.length; i++) {
414 const item = chunk[i]
415 if (typeof item === "string") {
416 this.push(item, "utf8")
417 } else {
418 this.push(item)
419 }
420 }
421 }))).pipe(
422 this.readLatch.whenOpen,
423 Effect.provideContext(context),
424 Effect.runFork
425 )
426 this.fiber.addObserver((exit) => {
427 this.fiber = undefined
428 if (Exit.isSuccess(exit)) {
429 this.push(null)
430 } else {
431 this.destroy(Cause.squash(exit.cause) as any)
432 }
433 })
434 }
435
436 override _read(_size: number): void {
437 this.readLatch.openUnsafe()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected