( self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>, f: (d: OutElem) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1> )
| 2455 | ) |
| 2456 | |
| 2457 | const flatMapSequential = < |
| 2458 | OutElem, |
| 2459 | OutErr, |
| 2460 | OutDone, |
| 2461 | InElem, |
| 2462 | InErr, |
| 2463 | InDone, |
| 2464 | Env, |
| 2465 | OutElem1, |
| 2466 | OutErr1, |
| 2467 | OutDone1, |
| 2468 | InElem1, |
| 2469 | InErr1, |
| 2470 | InDone1, |
| 2471 | Env1 |
| 2472 | >( |
| 2473 | self: Channel<OutElem, OutErr, OutDone, InElem, InErr, InDone, Env>, |
| 2474 | f: (d: OutElem) => Channel<OutElem1, OutErr1, OutDone1, InElem1, InErr1, InDone1, Env1> |
| 2475 | ): Channel< |
| 2476 | OutElem1, |
| 2477 | OutErr | OutErr1, |
| 2478 | OutDone, |
| 2479 | InElem & InElem1, |
| 2480 | InErr & InErr1, |
| 2481 | InDone & InDone1, |
| 2482 | Env | Env1 |
| 2483 | > => |
| 2484 | fromTransform((upstream, scope) => |
| 2485 | Effect.map(toTransform(self)(upstream, scope), (pull) => { |
| 2486 | let childPull: Effect.Effect<OutElem1, OutErr1, Env1> | undefined |
| 2487 | let childScope: Scope.Closeable | undefined |
| 2488 | const makePull: Pull.Pull< |
| 2489 | OutElem1, |
| 2490 | OutErr | OutErr1, |
| 2491 | OutDone, |
| 2492 | Env1 |
| 2493 | > = Effect.flatMap(pull, (value) => { |
| 2494 | childScope ??= Scope.forkUnsafe(scope) |
| 2495 | return Effect.flatMapEager(toTransform(f(value))(upstream, childScope), (pull) => { |
| 2496 | childPull = catchHalt(pull) as any |
| 2497 | return childPull! |
| 2498 | }) |
| 2499 | }) |
| 2500 | const catchHalt = Pull.catchDone((_) => { |
| 2501 | childPull = undefined |
| 2502 | // we can reuse the scope if the only finalizer is the "fork" one |
| 2503 | if (childScope!.state._tag === "Open" && childScope!.state.finalizers.size === 1) { |
| 2504 | return makePull |
| 2505 | } |
| 2506 | const close = Scope.close(childScope!, Exit.void) |
| 2507 | childScope = undefined |
| 2508 | return Effect.flatMap(close, () => makePull) |
| 2509 | }) |
| 2510 | return Effect.suspend(() => childPull ?? makePull) |
| 2511 | }) |
| 2512 | ) |
| 2513 | |
| 2514 | const flatMapConcurrent = < |
no test coverage detected