( self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>, f: (d: OutElem) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1> )
| 2622 | ) |
| 2623 | |
| 2624 | const flatMapSequential = < |
| 2625 | OutElem, |
| 2626 | OutErr, |
| 2627 | OutDone, |
| 2628 | InElem, |
| 2629 | InErr, |
| 2630 | InDone, |
| 2631 | Env, |
| 2632 | OutElem1, |
| 2633 | OutErr1, |
| 2634 | OutDone1, |
| 2635 | InElem1, |
| 2636 | InErr1, |
| 2637 | InDone1, |
| 2638 | Env1 |
| 2639 | >( |
| 2640 | self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>, |
| 2641 | f: (d: OutElem) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1> |
| 2642 | ): Channel< |
| 2643 | OutElem1, |
| 2644 | OutErr | OutErr1, |
| 2645 | OutDone, |
| 2646 | InElem & InElem1, |
| 2647 | InErr & InErr1, |
| 2648 | InDone & InDone1, |
| 2649 | Env | Env1 |
| 2650 | > => |
| 2651 | fromTransform((upstream, scope) => |
| 2652 | Effect.map(toTransform(self)(upstream, scope), (pull) => { |
| 2653 | let childPull: Effect.Effect<OutElem1, OutErr1, Env1> | undefined |
| 2654 | let childScope: Scope.Closeable | undefined |
| 2655 | const makePull: Pull.Pull< |
| 2656 | OutElem1, |
| 2657 | OutErr | OutErr1, |
| 2658 | OutDone, |
| 2659 | Env1 |
| 2660 | > = Effect.flatMap(pull, (value) => { |
| 2661 | childScope ??= Scope.forkUnsafe(scope) |
| 2662 | return Effect.flatMapEager(toTransform(f(value))(upstream, childScope), (pull) => { |
| 2663 | childPull = catchHalt(pull) as any |
| 2664 | return childPull! |
| 2665 | }) |
| 2666 | }) |
| 2667 | const catchHalt = Pull.catchDone((_) => { |
| 2668 | childPull = undefined |
| 2669 | // the scope can be reused if the inner channel left no finalizers behind |
| 2670 | if (childScope!.state._tag === "Empty") { |
| 2671 | return makePull |
| 2672 | } |
| 2673 | const close = Scope.close(childScope!, Exit.void) |
| 2674 | childScope = undefined |
| 2675 | return Effect.flatMap(close, () => makePull) |
| 2676 | }) |
| 2677 | return Effect.suspend(() => childPull ?? makePull) |
| 2678 | }) |
| 2679 | ) |
| 2680 | |
| 2681 | const flatMapConcurrent = < |
no test coverage detected