DeferHandle

zio.blocks.scope.DeferHandle
See theDeferHandle companion object
abstract class DeferHandle

A handle returned by Scope.defer that allows cancelling a registered finalizer before the scope closes.

When scope.defer(cleanup) is called, the cleanup action is registered to run when the scope closes, and a DeferHandle is returned. The handle can be used to remove that finalizer early, attempting to prevent it from running when the scope closes. If cancellation races with scope closure, the finalizer may already be in the process of running. This is useful when a resource is explicitly released before the scope ends, and running the finalizer again would be unnecessary or harmful.

Attributes

See also

Scope.defer for registering finalizers

Companion
object
Source
DeferHandle.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def cancel(): Unit

Cancels the registered finalizer so it will not run when the scope closes.

Cancels the registered finalizer so it will not run when the scope closes.

This method is thread-safe and idempotent: calling it multiple times has the same effect as calling it once. If the scope has already closed (and the finalizer has already run or been discarded), this method is a no-op.

Attributes

Source
DeferHandle.scala