PriorityTaskManager


@UnstableApi
class PriorityTaskManager


Allows tasks with associated priorities to control how they proceed relative to one another.

A task should call add to register with the manager and remove to unregister. A registered task will prevent tasks of lower priority from proceeding, and should call proceed, proceedNonBlocking or proceedOrThrow each time it wishes to check whether it is itself allowed to proceed.

Summary

Nested types

Thrown when task attempts to proceed when another registered task has a higher priority.

Public constructors

Public functions

Unit
add(priority: Int)

Register a new task.

Unit
proceed(priority: Int)

Blocks until the task is allowed to proceed.

Boolean

A non-blocking variant of proceed.

Unit
proceedOrThrow(priority: Int)

A throwing variant of proceed.

Unit
remove(priority: Int)

Unregister a task.

Public constructors

PriorityTaskManager

PriorityTaskManager()

Public functions

add

fun add(priority: Int): Unit

Register a new task. The task must call remove when done.

Parameters
priority: Int

The priority of the task. Larger values indicate higher priorities.

proceed

fun proceed(priority: Int): Unit

Blocks until the task is allowed to proceed.

Parameters
priority: Int

The priority of the task.

Throws
java.lang.InterruptedException

If the thread is interrupted.

proceedNonBlocking

fun proceedNonBlocking(priority: Int): Boolean

A non-blocking variant of proceed.

Parameters
priority: Int

The priority of the task.

Returns
Boolean

Whether the task is allowed to proceed.

proceedOrThrow

fun proceedOrThrow(priority: Int): Unit

A throwing variant of proceed.

Parameters
priority: Int

The priority of the task.

Throws
androidx.media3.common.PriorityTaskManager.PriorityTooLowException

If the task is not allowed to proceed.

remove

fun remove(priority: Int): Unit

Unregister a task.

Parameters
priority: Int

The priority of the task.