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

Function fromTransformStream

packages/effect/src/Channel.ts:1784–1816  ·  view source on GitHub ↗
(options: {
  readonly evaluate: LazyArg<TransformStream<I, O>>
  readonly onError: (error: unknown) => E
  readonly closeOnDone?: boolean | undefined
  readonly releaseLockOnEnd?: boolean | undefined
})

Source from the content-addressed store, hash-verified

1782 * @since 4.0.0
1783 */
1784export const fromTransformStream = <IE, I, O, E>(options: {
1785 readonly evaluate: LazyArg<TransformStream<I, O>>
1786 readonly onError: (error: unknown) => E
1787 readonly closeOnDone?: boolean | undefined
1788 readonly releaseLockOnEnd?: boolean | undefined
1789}): Channel<Arr.NonEmptyReadonlyArray<O>, IE | E, void, Arr.NonEmptyReadonlyArray<I>, IE> =>
1790 fromTransform((upstream, scope) => {
1791 const transform = options.evaluate()
1792 const exit = MutableRef.make<Exit.Exit<never, IE | E | Cause.Done> | undefined>(undefined)
1793 return pullIntoWritableStream({
1794 pull: upstream,
1795 writable: transform.writable,
1796 onError: options.onError,
1797 closeOnDone: options.closeOnDone
1798 }).pipe(
1799 Effect.catchCause((cause) => {
1800 if (!Pull.isDoneCause(cause)) {
1801 exit.current = Exit.failCause(cause as Cause.Cause<IE | E | Cause.Done>)
1802 }
1803 return Effect.void
1804 }),
1805 Effect.forkIn(scope),
1806 Effect.flatMap(() =>
1807 readableStreamToPullUnsafe({
1808 scope,
1809 exit,
1810 readable: transform.readable,
1811 onError: options.onError,
1812 releaseLockOnEnd: options.releaseLockOnEnd
1813 })
1814 )
1815 )
1816 })
1817
1818const readableStreamToPullUnsafe = <A, E, E2 = never>(options: {
1819 readonly scope: Scope.Scope

Callers

nothing calls this directly

Calls 6

pullIntoWritableStreamFunction · 0.85
fromTransformFunction · 0.70
evaluateMethod · 0.65
makeMethod · 0.65
pipeMethod · 0.65

Tested by

no test coverage detected