You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds **resource scopes**: scopes which allow attaching resources
(`useInScope` / `releaseAfterScope` style), but are not full concurrency
scopes — no forking, no threads started while the body runs. Every
concurrency scope can be used where a resource scope is expected (via
subtyping: `OxUnsupervised extends ResourceScope`). This is ox's
analogue of `scala.util.Using.Manager`, and lets methods declare exactly
the capability they need (`using ResourceScope` — attach cleanup,
without claiming the ability to fork).
Design highlights (adversarially critiqued before implementation):
- **Compile-time guard**: `resourceScope` cannot be started where a
concurrency scope is lexically visible (via a `NotGiven`-based given
with a custom error message) — forks started within a lexically visible
resource scope could outlive it. The recommended structure is extracting
the scope to a capability-free method.
- **Finalizer-list freeze**: registering a resource after its scope
ended (possible only via explicitly-leaked capabilities) now throws
`IllegalStateException` instead of being silently lost; `useInScope`
releases the just-acquired resource in that case, so cleanup is never
lost. Applies uniformly to concurrency scopes.
- **Binary compatibility preserved**: the four resource functions now
take `using ResourceScope`; bridges with the old `using OxUnsupervised`
JVM signatures are kept via `@targetName` (with distinct Scala-level
names, avoiding overload ambiguity) — MiMa passes with no new filters.
Source compatibility is unaffected.
- Nesting/`ForkLocal` semantics pinned by tests: resources attach to the
nearest enclosing scope; resource-scope finalizers see the fork-local
values of the scope's own level.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
"This operation must be run within a `supervised`, `supervisedError` or `unsupervised` block. Alternatively, you must require that the enclosing method is run within a scope, by adding a `using OxUnsupervised` parameter list."
0 commit comments