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

Function close

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

Source from the content-addressed store, hash-verified

3249 })
3250 },
3251 close(this: ScopeImpl, exit) {
3252 return core.suspend(() => {
3253 if (this.state._tag === "Closed") {
3254 return core.void
3255 }
3256 const finalizers = Array.from(this.state.finalizers.values()).reverse()
3257 this.state = { _tag: "Closed", exit }
3258 if (finalizers.length === 0) {
3259 return core.void
3260 }
3261 return executionStrategy.isSequential(this.strategy) ?
3262 pipe(
3263 core.forEachSequential(finalizers, (fin) => core.exit(fin(exit))),
3264 core.flatMap((results) =>
3265 pipe(
3266 core.exitCollectAll(results),
3267 Option.map(core.exitAsVoid),
3268 Option.getOrElse(() => core.exitVoid)
3269 )
3270 )
3271 ) :
3272 executionStrategy.isParallel(this.strategy) ?
3273 pipe(
3274 forEachParUnbounded(finalizers, (fin) => core.exit(fin(exit)), false),
3275 core.flatMap((results) =>
3276 pipe(
3277 core.exitCollectAll(results, { parallel: true }),
3278 Option.map(core.exitAsVoid),
3279 Option.getOrElse(() => core.exitVoid)
3280 )
3281 )
3282 ) :
3283 pipe(
3284 forEachParN(finalizers, this.strategy.parallelism, (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 })
3294 },
3295 addFinalizer(this: ScopeImpl, fin) {
3296 return core.suspend(() => {
3297 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