OnceFlag

class OnceFlag

A resettable flag that runs a block at most once between resets.

The flag is set before the block is invoked, so a block that throws still consumes the flag and later calls do not run.

This class is not thread-safe.

Constructors

Link copied to clipboard
constructor()

Creates a flag that has not run yet.

Properties

Link copied to clipboard

true once runOnce has accepted a block, until reset.

Functions

Link copied to clipboard
fun reset()

Clears the flag so the next runOnce runs its block again.

Link copied to clipboard
fun runOnce(block: () -> Unit): Boolean

Runs block if no block has run since construction or the last reset, and returns true only for that first call.