(
register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R>,
bufferSize?: number | "unbounded" | {
readonly bufferSize?: number | undefined
readonly strategy?: "dropping" | "sliding" | "suspend" | undefined
} | undefined
)
| 540 | |
| 541 | /** @internal */ |
| 542 | export const asyncEffect = <A, E = never, R = never>( |
| 543 | register: (emit: Emit.Emit<R, E, A, void>) => Effect.Effect<unknown, E, R>, |
| 544 | bufferSize?: number | "unbounded" | { |
| 545 | readonly bufferSize?: number | undefined |
| 546 | readonly strategy?: "dropping" | "sliding" | "suspend" | undefined |
| 547 | } | undefined |
| 548 | ): Stream.Stream<A, E, R> => |
| 549 | pipe( |
| 550 | Effect.acquireRelease( |
| 551 | queueFromBufferOptions<A, E>(bufferSize), |
| 552 | (queue) => Queue.shutdown(queue) |
| 553 | ), |
| 554 | Effect.flatMap((output) => |
| 555 | pipe( |
| 556 | Effect.runtime<R>(), |
| 557 | Effect.flatMap((runtime) => |
| 558 | pipe( |
| 559 | register( |
| 560 | emit.make((k) => |
| 561 | pipe( |
| 562 | InternalTake.fromPull(k), |
| 563 | Effect.flatMap((take) => Queue.offer(output, take)), |
| 564 | Effect.asVoid, |
| 565 | Runtime.runPromiseExit(runtime) |
| 566 | ).then((exit) => { |
| 567 | if (Exit.isFailure(exit)) { |
| 568 | if (!Cause.isInterrupted(exit.cause)) { |
| 569 | throw Cause.squash(exit.cause) |
| 570 | } |
| 571 | } |
| 572 | }) |
| 573 | ) |
| 574 | ), |
| 575 | Effect.map(() => { |
| 576 | const loop: Channel.Channel<Chunk.Chunk<A>, unknown, E, unknown, void, unknown> = pipe( |
| 577 | Queue.take(output), |
| 578 | Effect.flatMap(InternalTake.done), |
| 579 | Effect.match({ |
| 580 | onFailure: (maybeError) => |
| 581 | pipe( |
| 582 | core.fromEffect(Queue.shutdown(output)), |
| 583 | channel.zipRight(Option.match(maybeError, { onNone: () => core.void, onSome: core.fail })) |
| 584 | ), |
| 585 | onSuccess: (chunk) => pipe(core.write(chunk), core.flatMap(() => loop)) |
| 586 | }), |
| 587 | channel.unwrap |
| 588 | ) |
| 589 | return loop |
| 590 | }) |
| 591 | ) |
| 592 | ) |
| 593 | ) |
| 594 | ), |
| 595 | channel.unwrapScoped, |
| 596 | fromChannel |
| 597 | ) |
| 598 | |
| 599 | const mailboxFromBufferOptionsPush = <A, E>( |
nothing calls this directly
no test coverage detected