MCPcopy Create free account
hub / github.com/Effect-TS/effect / concatChannels

Function concatChannels

packages/effect/src/Stream.ts:3101–3124  ·  view source on GitHub ↗
(self: Stream<A, E, R>, that: Stream<A, E, R>)

Source from the content-addressed store, hash-verified

3099// Yields the channel of each non-`concat` stream in a chain, in order. A
3100// `suspend` part is evaluated when it is reached and its result joins the chain
3101function* concatChannels<A, E, R>(self: Stream<A, E, R>, that: Stream<A, E, R>) {
3102 const stack = [that, self]
3103 while (stack.length > 0) {
3104 const stream = stack.pop()!
3105 const parts = concatParts.get(stream)
3106 if (parts !== undefined) {
3107 stack.push(parts[1], parts[0])
3108 continue
3109 }
3110 const evaluate = suspendedStreams.get(stream)
3111 if (evaluate === undefined) {
3112 yield stream.channel
3113 continue
3114 }
3115 // Evaluated here rather than in an effect, so retrying an interrupted pull
3116 // cannot evaluate it twice. `Channel.empty` keeps a yield point
3117 try {
3118 stack.push(evaluate())
3119 } catch (defect) {
3120 stack.push(die(defect))
3121 }
3122 yield Channel.empty
3123 }
3124}
3125
3126/**
3127 * Prepends the values from the provided iterable before the stream's elements.

Callers 1

Stream.tsFile · 0.85

Calls 4

evaluateFunction · 0.70
dieFunction · 0.70
getMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected