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

Function fromAsyncIterable

packages/effect/src/internal/stream.ts:2968–2987  ·  view source on GitHub ↗
(
  iterable: AsyncIterable<A>,
  onError: (e: unknown) => E
)

Source from the content-addressed store, hash-verified

2966
2967/** @internal */
2968export const fromAsyncIterable = <A, E>(
2969 iterable: AsyncIterable<A>,
2970 onError: (e: unknown) => E
2971) =>
2972 pipe(
2973 Effect.acquireRelease(
2974 Effect.sync(() => iterable[Symbol.asyncIterator]()),
2975 (iterator) => iterator.return ? Effect.promise(async () => iterator.return!()) : Effect.void
2976 ),
2977 Effect.map((iterator) =>
2978 repeatEffectOption(pipe(
2979 Effect.tryPromise({
2980 try: async () => iterator.next(),
2981 catch: (reason) => Option.some(onError(reason))
2982 }),
2983 Effect.flatMap((result) => result.done ? Effect.fail(Option.none()) : Effect.succeed(result.value))
2984 ))
2985 ),
2986 unwrapScoped
2987 )
2988
2989/** @internal */
2990export const fromChannel = <A, E, R>(

Callers

nothing calls this directly

Calls 7

repeatEffectOptionFunction · 0.85
syncMethod · 0.80
pipeFunction · 0.70
mapMethod · 0.65
nextMethod · 0.65
failMethod · 0.65
onErrorFunction · 0.50

Tested by

no test coverage detected