ScopedCounter

class ScopedCounter(maxDepth: Int, onOverflow: () -> Nothing)

A thread-safe counter that tracks a depth value within nested scopes.

Parameters

maxDepth

maximum allowed depth. If exceeded, onOverflow is invoked

onOverflow

action to perform when the maximum depth is exceeded

Constructors

Link copied to clipboard
constructor(maxDepth: Int, onOverflow: () -> Nothing)

Functions

Link copied to clipboard
fun get(): Int

The current depth of the counter.

Link copied to clipboard
inline fun <T> incrementScoped(block: () -> T): T

Increments the counter, executes block, and decrements the counter when block completes. If the counter exceeds maxDepth, onOverflow is invoked before executing block.