Spinner

class Spinner

A spinner implements utility functions for spinning in a loop.

Constructors

Link copied to clipboard
constructor()

Creates an instance of the Spinner class.

constructor(threadCount: Int)

Creates an instance of the Spinner class.

constructor(threadCounter: () -> Int)

Creates an instance of the Spinner class.

Properties

Link copied to clipboard

Determines whether the spinner should actually spin in a loop or if it should exit immediately.

Functions

Link copied to clipboard
fun pollElapsedTime(startTimeNano: Long): Long

Calculates the elapsed time in nanoseconds since the provided start time.

Link copied to clipboard

Defines the limit for iterations in a spin-loop before it exits.

Link copied to clipboard

Determines the limit for the number of iterations the spin-loop should perform before yielding to other threads.

Link copied to clipboard
inline fun <T> Spinner.spinWaitBoundedFor(getter: () -> T?): T?

Waits for the result of the given getter function in the spin-loop until the result is not null. Exits the spin-loop after a certain number of spin-loop iterations.

Link copied to clipboard
inline fun Spinner.spinWaitBoundedUntil(condition: () -> Boolean): Boolean

Waits in the spin-loop until the given condition is true. Exits the spin-loop after a certain number of spin-loop iterations --- typically, in this case, one may want to fall back into some blocking synchronization.

Link copied to clipboard
inline fun spinWaitTimedUntil(timeoutNano: Long, condition: () -> Boolean): Long

Waits in a spin-loop until the specified condition is met or the timeout is reached.

Link copied to clipboard
inline fun spinWaitUntil(condition: () -> Boolean)

Waits in the spin-loop until the given condition is true with periodical yielding to other threads.