Package com.castlabs.utils

# Class HandlerRunner

java.lang.Object
com.castlabs.utils.HandlerRunner

public final class HandlerRunner extends Object
Helper class to execute `Callable`s on specific `Handler`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static boolean`
  `DEBUG`
  Set to true to get more logging

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HandlerRunner(Handler handler)`
  Creates `HandlerRunner` instance.
  `HandlerRunner(Handler handler, long timeoutMs, boolean verifyThread)`
  Creates `HandlerRunner` instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `runOn(Runnable runnable)`
  Runs `Runnable` on the `Handler` thread and waits for the completion.
  `<T> T`
  `runOn(Callable<T> callable, T valueOnError)`
  Runs `Callable` on the `Handler` thread and waits for the result.
  `<T> T`
  `runOnNullable(Callable<T> callable, T valueOnError)`
  Runs `Callable` on the `Handler` thread and waits for the result.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEBUG

    public static boolean DEBUG
    Set to true to get more logging

- ## Constructor Details

  - ### HandlerRunner

    public HandlerRunner(@NonNull Handler handler)
    Creates `HandlerRunner` instance.
    Parameters:
      `handler` - The handler with the looper to execute the callable on

  - ### HandlerRunner

    public HandlerRunner(@NonNull Handler handler, long timeoutMs, boolean verifyThread)
    Creates `HandlerRunner` instance.
    Parameters:
      `handler` - The handler with the looper to execute the callable on
      `timeoutMs` - The timeout for the operation in milliseconds
      `verifyThread` - true if thread verification is enabled, false otherwise

- ## Method Details

  - ### runOn

    @NonNull public <T> T runOn(@NonNull Callable<T> callable, @NonNull T valueOnError)
    Runs `Callable` on the `Handler` thread and waits for the result.
    Type Parameters:
      `T` - The callable result type.
    Parameters:
      `callable` - The callable to run.
      `valueOnError` - The value to return if execution fails or if the callable returns `null`. Must not be `null`.
    Returns:
      The callable result if non-null, or `valueOnError` otherwise.

  - ### runOnNullable

    @Nullable public <T> T runOnNullable(@NonNull Callable<T> callable, @Nullable T valueOnError)
    Runs `Callable` on the `Handler` thread and waits for the result.
    Type Parameters:
      `T` - The result type returned by the callable.
    Parameters:
      `callable` - `Callable` to execute
      `valueOnError` - Value to return upon failure
    Returns:
      The callable result, or `valueOnError` if execution fails. May be `null`.

  - ### runOn

    public void runOn(@NonNull Runnable runnable)
    Runs `Runnable` on the `Handler` thread and waits for the completion.
    Parameters:
      `runnable` - `Runnable` to execute