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

Function finalize

packages/effect/src/internal/stream.ts:2168–2208  ·  view source on GitHub ↗
(endTake: Exit.Exit<never, Option.Option<E>>)

Source from the content-addressed store, hash-verified

2166 )
2167 )
2168 const finalize = (endTake: Exit.Exit<never, Option.Option<E>>): Effect.Effect<void> =>
2169 // Make sure that no queues are currently being added
2170 queuesLock.withPermits(1)(
2171 pipe(
2172 Ref.set(
2173 newQueue,
2174 pipe(
2175 // All newly created queues should end immediately
2176 Queue.bounded<Exit.Exit<A, Option.Option<E>>>(1),
2177 Effect.tap((queue) => Queue.offer(queue, endTake)),
2178 Effect.flatMap((queue) => {
2179 const id = newDistributedWithDynamicId()
2180 return pipe(
2181 Ref.update(queuesRef, (map) => map.set(id, queue)),
2182 Effect.as(Tuple.make(id, queue))
2183 )
2184 })
2185 )
2186 ),
2187 Effect.zipRight(
2188 pipe(
2189 Ref.get(queuesRef),
2190 Effect.flatMap((map) =>
2191 pipe(
2192 Chunk.fromIterable(map.values()),
2193 Effect.forEach((queue) =>
2194 pipe(
2195 Queue.offer(queue, endTake),
2196 Effect.catchSomeCause((cause) =>
2197 Cause.isInterrupted(cause) ? Option.some(Effect.void) : Option.none()
2198 )
2199 )
2200 )
2201 )
2202 )
2203 )
2204 ),
2205 Effect.zipRight(done(endTake)),
2206 Effect.asVoid
2207 )
2208 )
2209 yield* pipe(
2210 self,
2211 runForEachScoped(offer),

Callers 1

stream.tsFile · 0.85

Calls 11

withPermitsMethod · 0.80
isInterruptedMethod · 0.80
pipeFunction · 0.70
doneFunction · 0.70
setMethod · 0.65
offerMethod · 0.65
updateMethod · 0.65
makeMethod · 0.65
getMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected