Module is.codion.common.model
Package is.codion.common.model.worker
Interface ProgressWorker.Builder<T,V>
- Type Parameters:
T- the worker result typeV- 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 Summary
Modifier and TypeMethodDescriptionbuild()dispatcher(Dispatcher dispatcher) Overrides theDispatcherused to run the handlers,Dispatcher.instance()by default.execute()Builds and executes a newProgressWorkerbased on this builderonCancelled(Runnable onCancelled) Adds a handler called on the UI thread if the background task is cancelled viaProgressWorker.cancel(boolean)or if it throws aCancelException.Adds a handler called on the UI thread when the task is done running, successfully or not, before the result is processed.onException(Consumer<Exception> onException) Adds a handler called on the UI thread if an exception occurred.onInterrupted(Runnable onInterrupted) Adds a handler called on the UI thread if the background task was interrupted.onProgress(Consumer<Integer> onProgress) Adds a handler called on the UI thread when progress is reported.Adds a handler called on the UI thread when chunks are available for publishing.Adds a handler called on the UI thread when the result of a successful run is available, after anyonSuccess(Runnable)handlers.Adds a handler called on the UI thread before background processing is started.Adds a handler called on the UI thread after a successful task run, before anyonResult(Consumer)handlers.
-
Method Details
-
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
Adds a handler called on the UI thread after a successful task run, before anyonResult(Consumer)handlers.- Parameters:
onSuccess- the handler to add- Returns:
- this builder instance
-
onResult
Adds a handler called on the UI thread when the result of a successful run is available, after anyonSuccess(Runnable)handlers.- Parameters:
onResult- the handler to add- Returns:
- this builder instance
-
onProgress
Adds a handler called on the UI thread when progress is reported.- Parameters:
onProgress- the handler to add- Returns:
- this builder instance
-
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
Adds a handler called on the UI thread if an exception occurred.- Parameters:
onException- the handler to add- Returns:
- this builder instance
-
onCancelled
Adds a handler called on the UI thread if the background task is cancelled viaProgressWorker.cancel(boolean)or if it throws aCancelException.- Parameters:
onCancelled- the handler to add- Returns:
- this builder instance
-
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
Overrides theDispatcherused to run the handlers,Dispatcher.instance()by default.Provided primarily for testing,
Dispatcher.SYNCHRONOUSruns 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 newProgressWorkerbased on this builder- Returns:
- a
ProgressWorkerbased on this builder
-
build
ProgressWorker<T,V> build()- Returns:
- a
ProgressWorkerbased on this builder
-