ScopeType

PackageAxial

Scope

A Scope owns finalizers for resources and child fibers. Closing it runs registered cleanup in reverse order, at most once, and waits for cleanup before returning.

Most application code should not construct or mutate Scope directly. Use the Flow-level operations:

A forked fiber has its own scope and releases its scoped resources when it settles. Flow.zipPar, Flow.sequencePar, and Flow.traversePar run their flows in one shared scope; Flow.race gives each branch its own scope, and each timed flow runs in its own scope. Whichever scope holds the value the caller receives stays open: it moves to the caller's scope and closes with it, so its resources live as if the caller had acquired them. Any other scope is released — a failed parallel group or a failed race winner closes before the combinator returns, a timed flow that fails or times out closes before the combinator returns (on timeout, before the fallback runs), and a race loser closes once it is interrupted, which may be after race returns.

This runtime lifetime differs from F# use and use!, which dispose when their lexical computation-expression body exits. A Flow scope can span functions, subflows, stream pulls, and child fibers.

Read the Scopes guide for a timeline of root, lexical, child, and nested lifetimes before using the low-level members listed below.

Scope transfer per combinator

Combinator What happens to its scoped resources
Flow.zipPar, Flow.sequencePar, Flow.traversePar, Flow.forEachPar Move to the caller's scope when every flow succeeds. Released before it returns when any flow fails.
Flow.race The winner's move to the caller's scope if it succeeds. The loser's are released once it has been interrupted.
Flow.timeout, Flow.timeoutToOk, Flow.timeoutWith Move to the caller's scope when the flow succeeds in time. Released when it fails or times out.
Flow.fork and its variants Stay with the fiber and are released when it settles. Fiber.join gives you the value, not the resources.
Flow.forkResource The resource is acquired in a fiber and its release goes to the caller's scope.
The per-worker resource of Flow.traverseParUsing and Flow.forEachParUsing Released when that worker finishes.

Specification

Kind
Type
Members
6
Examples
0
``.ctor``Signature
Scope()
AddAsyncDisposableSignature
this.AddAsyncDisposable
AddChildSignature
this.AddChild
AddDisposableSignature
this.AddDisposable
AddFinalizerSignature
this.AddFinalizer

Summary

NameSignatureSynopsis
Operations
``.ctor``Scope()No description available.
AddAsyncDisposablethis.AddAsyncDisposableNo description available.
AddChildthis.AddChildNo description available.
AddDisposablethis.AddDisposableNo description available.
AddFinalizerthis.AddFinalizerNo description available.
Closethis.CloseNo description available.

Operations

kind:typekind:member

``.ctor``

Scope()
Member

Returns

Scope
kind:member

AddAsyncDisposable

this.AddAsyncDisposable
Member

Parameters

NameTypeDescription
resourceIAsyncDisposable

Returns

unit
kind:member

AddChild

this.AddChild
Member

Returns

Scope
kind:member

AddDisposable

this.AddDisposable
Member

Parameters

NameTypeDescription
resourceIDisposable

Returns

unit
kind:member

AddFinalizer

this.AddFinalizer
Member

Parameters

NameTypeDescription
finalizerFinalizer

Returns

unit
kind:member

Close

this.Close
Member

Parameters

NameTypeDescription
cancellationTokenCancellationToken

Returns

Deed