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

Function close

packages/effect/src/internal/fiberRuntime.ts:3261–3304  ·  view source on GitHub ↗
(this: ScopeImpl, exit)

Source from the content-addressed store, hash-verified

3259 })
3260 },
3261 close(this: ScopeImpl, exit) {
3262 return core.suspend(() => {
3263 if (this.state._tag === "Closed") {
3264 return core.void
3265 }
3266 const finalizers = Array.from(this.state.finalizers.values()).reverse()
3267 this.state = { _tag: "Closed", exit }
3268 if (finalizers.length === 0) {
3269 return core.void
3270 }
3271 return executionStrategy.isSequential(this.strategy) ?
3272 pipe(
3273 core.forEachSequential(finalizers, (fin) => core.exit(fin(exit))),
3274 core.flatMap((results) =>
3275 pipe(
3276 core.exitCollectAll(results),
3277 Option.map(core.exitAsVoid),
3278 Option.getOrElse(() => core.exitVoid)
3279 )
3280 )
3281 ) :
3282 executionStrategy.isParallel(this.strategy) ?
3283 pipe(
3284 forEachParUnbounded(finalizers, (fin) => core.exit(fin(exit)), false),
3285 core.flatMap((results) =>
3286 pipe(
3287 core.exitCollectAll(results, { parallel: true }),
3288 Option.map(core.exitAsVoid),
3289 Option.getOrElse(() => core.exitVoid)
3290 )
3291 )
3292 ) :
3293 pipe(
3294 forEachParN(finalizers, this.strategy.parallelism, (fin) => core.exit(fin(exit)), false),
3295 core.flatMap((results) =>
3296 pipe(
3297 core.exitCollectAll(results, { parallel: true }),
3298 Option.map(core.exitAsVoid),
3299 Option.getOrElse(() => core.exitVoid)
3300 )
3301 )
3302 )
3303 })
3304 },
3305 addFinalizer(this: ScopeImpl, fin) {
3306 return core.suspend(() => {
3307 if (this.state._tag === "Closed") {

Callers

nothing calls this directly

Calls 6

finFunction · 0.85
forEachParUnboundedFunction · 0.85
forEachParNFunction · 0.85
pipeFunction · 0.70
mapMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected