Interface ProgressWorker.Builder<T,V>

Type Parameters:
T - the worker result type
V - the intermediate result type
Enclosing class:
ProgressWorker<T,V>

public static sealed interface ProgressWorker.Builder<T,V>

Builds a ProgressWorker instance.

Each handler method can be called multiple times to add multiple handlers. All handlers are called in the order they were added. When using a task that implements a handler interface (e.g. ProgressWorker.TaskHandler), those handler methods are added first, and any handlers added via this builder are called after.

  • Method Details

    • onStarted

      ProgressWorker.Builder<T,V> onStarted(Runnable onStarted)
      Adds a handler called on the UI thread before background processing is started.
      Parameters:
      onStarted - the handler to add
      Returns:
      this builder instance
    • onDone

      Adds a handler called on the UI thread when the task is done running, successfully or not, before the result is processed.
      Parameters:
      onDone - the handler to add
      Returns:
      this builder instance
    • onSuccess

      ProgressWorker.Builder<T,V> onSuccess(Runnable onSuccess)
      Adds a handler called on the UI thread after a successful task run, before any onResult(Consumer) handlers.
      Parameters:
      onSuccess - the handler to add
      Returns:
      this builder instance
    • onResult

      ProgressWorker.Builder<T,V> onResult(Consumer<T> onResult)
      Adds a handler called on the UI thread when the result of a successful run is available, after any onSuccess(Runnable) handlers.
      Parameters:
      onResult - the handler to add
      Returns:
      this builder instance
    • onProgress

      ProgressWorker.Builder<T,V> onProgress(Consumer<Integer> onProgress)
      Adds a handler called on the UI thread when progress is reported.
      Parameters:
      onProgress - the handler to add
      Returns:
      this builder instance
    • onPublish

      ProgressWorker.Builder<T,V> onPublish(Consumer<List<V>> onPublish)
      Adds a handler called on the UI thread when chunks are available for publishing.
      Parameters:
      onPublish - the handler to add
      Returns:
      this builder instance
    • onException

      ProgressWorker.Builder<T,V> onException(Consumer<Exception> onException)
      Adds a handler called on the UI thread if an exception occurred.
      Parameters:
      onException - the handler to add
      Returns:
      this builder instance
    • onCancelled

      ProgressWorker.Builder<T,V> onCancelled(Runnable onCancelled)
      Adds a handler called on the UI thread if the background task is cancelled via ProgressWorker.cancel(boolean) or if it throws a CancelException.
      Parameters:
      onCancelled - the handler to add
      Returns:
      this builder instance
    • onInterrupted

      ProgressWorker.Builder<T,V> onInterrupted(Runnable onInterrupted)
      Adds a handler called on the UI thread if the background task was interrupted.
      Parameters:
      onInterrupted - the handler to add
      Returns:
      this builder instance
    • dispatcher

      ProgressWorker.Builder<T,V> dispatcher(Dispatcher dispatcher)
      Overrides the Dispatcher used to run the handlers, Dispatcher.instance() by default.

      Provided primarily for testing, Dispatcher.SYNCHRONOUS runs the handlers synchronously on the calling thread.

      Parameters:
      dispatcher - the dispatcher to use
      Returns:
      this builder instance
    • execute

      ProgressWorker<T,V> execute()
      Builds and executes a new ProgressWorker based on this builder
      Returns:
      a ProgressWorker based on this builder
    • build

      ProgressWorker<T,V> build()
      Returns:
      a ProgressWorker based on this builder