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

Method stream

packages/ui/native/src/NativeHttpClient.ts:384–418  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

382 }
383
384 get stream(): Stream.Stream<Uint8Array, HttpClientError.HttpClientError> {
385 return Stream.callback<Uint8Array, HttpClientError.HttpClientError>(
386 (queue) =>
387 Effect.acquireRelease(
388 Effect.sync(() => {
389 const exchange = this.exchange
390 const fail = (error: HttpClientError.HttpClientError) => {
391 Queue.failCauseUnsafe(queue, Cause.fail(error))
392 }
393 const unreadable = this.unreadable()
394 if (unreadable) return fail(unreadable)
395 this.streamed = true
396 const flush = () => {
397 const chunks = exchange.chunks
398 for (const chunk of chunks) {
399 if (chunk === "") continue
400 const bytes = this.bytes(chunk)
401 if (!(bytes instanceof Uint8Array)) return fail(bytes)
402 Queue.offerUnsafe(queue, bytes)
403 }
404 // Release consumed chunks from long-lived streams.
405 chunks.length = 0
406 if (exchange.error === null) Queue.endUnsafe(queue)
407 else if (exchange.error !== undefined) {
408 fail(this.failed(exchange.error))
409 }
410 }
411 exchange.listeners.add(flush)
412 flush()
413 return flush
414 }),
415 (flush) => Effect.sync(() => flush && this.exchange.listeners.delete(flush))
416 )
417 )
418 }
419
420 get text(): Effect.Effect<string, HttpClientError.HttpClientError> {
421 return this.binary

Callers

nothing calls this directly

Calls 6

unreadableMethod · 0.95
failFunction · 0.70
addMethod · 0.65
deleteMethod · 0.65
flushFunction · 0.50
syncMethod · 0.45

Tested by

no test coverage detected