OneTimeEvent

class OneTimeEvent<T>(content: T)(source)

Event content that can be consumed at most once per wrapper instance.

getContentIfNotHandled atomically marks the instance consumed before returning its content. Competing consumers share that flag; only one can obtain non-null content. This does not acknowledge a completed UI action, retry a cancelled action, or persist across process death. A newly created wrapper has its own consumption flag, even for equal content.

Type Parameters

T

The content type, which may be nullable.

Constructors

Link copied to clipboard
constructor(content: T)

Functions

Link copied to clipboard

Atomically marks this event consumed, returning its content only on the first call.

Link copied to clipboard
fun peekContent(): T

Returns the content without marking it as handled.