MCPcopy
hub / github.com/Effect-TS/effect / DrainChildExecutors

Class DrainChildExecutors

packages/effect/src/internal/channel/subexecutor.ts:155–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153 * @internal
154 */
155export class DrainChildExecutors<in out R> implements Subexecutor<R> {
156 readonly _tag: OP_DRAIN_CHILD_EXECUTORS = OP_DRAIN_CHILD_EXECUTORS
157
158 constructor(
159 readonly upstreamExecutor: ErasedExecutor<R>,
160 readonly lastDone: unknown,
161 readonly activeChildExecutors: ReadonlyArray<PullFromChild<R> | undefined>,
162 readonly upstreamDone: Exit.Exit<unknown, unknown>,
163 readonly combineChildResults: (x: unknown, y: unknown) => unknown,
164 readonly combineWithChildResult: (x: unknown, y: unknown) => unknown,
165 readonly onPull: (
166 request: UpstreamPullRequest.UpstreamPullRequest<unknown>
167 ) => UpstreamPullStrategy.UpstreamPullStrategy<unknown>
168 ) {
169 }
170
171 close(exit: Exit.Exit<unknown, unknown>): Effect.Effect<unknown, never, R> | undefined {
172 const fin1 = this.upstreamExecutor.close(exit)
173 const fins = [
174 ...this.activeChildExecutors.map((child) => (child !== undefined ?
175 child.childExecutor.close(exit) :
176 undefined)
177 ),
178 fin1
179 ]
180 const result = fins.reduce(
181 (acc: Effect.Effect<Exit.Exit<unknown, unknown>, never, R> | undefined, next) => {
182 if (acc !== undefined && next !== undefined) {
183 return Effect.zipWith(
184 acc,
185 Effect.exit(next),
186 (exit1, exit2) => Exit.zipRight(exit1, exit2)
187 )
188 } else if (acc !== undefined) {
189 return acc
190 } else if (next !== undefined) {
191 return Effect.exit(next)
192 } else {
193 return undefined
194 }
195 },
196 undefined
197 )
198 return result === undefined ? result : result
199 }
200
201 enqueuePullFromChild(child: PullFromChild<R>): Subexecutor<R> {
202 return new DrainChildExecutors(
203 this.upstreamExecutor,
204 this.lastDone,
205 [...this.activeChildExecutors, child],
206 this.upstreamDone,
207 this.combineChildResults,
208 this.combineWithChildResult,
209 this.onPull
210 )
211 }
212}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected