MCPcopy Index your code
hub / github.com/Effect-TS/effect / PullFromUpstream

Class PullFromUpstream

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

Source from the content-addressed store, hash-verified

85 * @internal
86 */
87export class PullFromUpstream<in out R> implements Subexecutor<R> {
88 readonly _tag: OP_PULL_FROM_UPSTREAM = OP_PULL_FROM_UPSTREAM
89
90 constructor(
91 readonly upstreamExecutor: ErasedExecutor<R>,
92 readonly createChild: (value: unknown) => ErasedChannel<R>,
93 readonly lastDone: unknown,
94 readonly activeChildExecutors: ReadonlyArray<PullFromChild<R> | undefined>,
95 readonly combineChildResults: (x: unknown, y: unknown) => unknown,
96 readonly combineWithChildResult: (x: unknown, y: unknown) => unknown,
97 readonly onPull: (
98 request: UpstreamPullRequest.UpstreamPullRequest<unknown>
99 ) => UpstreamPullStrategy.UpstreamPullStrategy<unknown>,
100 readonly onEmit: (value: unknown) => ChildExecutorDecision.ChildExecutorDecision
101 ) {
102 }
103
104 close(exit: Exit.Exit<unknown, unknown>): Effect.Effect<unknown, never, R> | undefined {
105 const fin1 = this.upstreamExecutor.close(exit)
106 const fins = [
107 ...this.activeChildExecutors.map((child) =>
108 child !== undefined ?
109 child.childExecutor.close(exit) :
110 undefined
111 ),
112 fin1
113 ]
114 const result = fins.reduce(
115 (acc: Effect.Effect<Exit.Exit<unknown, unknown>, never, R> | undefined, next) => {
116 if (acc !== undefined && next !== undefined) {
117 return Effect.zipWith(
118 acc,
119 Effect.exit(next),
120 (exit1, exit2) => Exit.zipRight(exit1, exit2)
121 )
122 } else if (acc !== undefined) {
123 return acc
124 } else if (next !== undefined) {
125 return Effect.exit(next)
126 } else {
127 return undefined
128 }
129 },
130 undefined
131 )
132 return result === undefined ? result : result
133 }
134
135 enqueuePullFromChild(child: PullFromChild<R>): Subexecutor<R> {
136 return new PullFromUpstream(
137 this.upstreamExecutor,
138 this.createChild,
139 this.lastDone,
140 [...this.activeChildExecutors, child],
141 this.combineChildResults,
142 this.combineWithChildResult,
143 this.onPull,
144 this.onEmit

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected