Skip to content

ProgressReporter

fun interface ProgressReporter

SAM interface to communicate progress to a caller.

Instances of this interface can be created by a caller and passed to a downstream user. The downstream user can then call the report function to communicate its progress to the caller.

If you are attempting to call a function which requires an instance of ProgressReporter, but you do not care about the progress events, you can use emptyProgressReporter to access a no-op implementation.

Types

Companion

object Companion

Functions

map

Creates a new reporter that applies transform to each progress event it receives.

reduceToInterval

fun ProgressReporter.reduceToInterval(
    min: Double, 
    max: Double, 
    treatDoneAs: Progress.Loading.Quantified = defaultDone, 
    treatUnquantifiedAs: Progress.Loading.Quantified = defaultUnquantified
): ProgressReporter

Creates a new reporter that proportionally confines progress events to the min..max range.

Parameters

  • treatDoneAs: When a Progress.Done is received, it will be treated as if that value was received.

  • treatUnquantifiedAs: When a Progress.Loading.Unquantified is received, it will be treated as if that value was received.

fun ProgressReporter.reduceToInterval(
    interval: ClosedFloatingPointRange<Double>, 
    treatDoneAs: Progress.Loading.Quantified = defaultDone, 
    treatUnquantifiedAs: Progress.Loading.Quantified = defaultUnquantified
): ProgressReporter

Creates a new reporter that proportionally confines progress events to interval.

Example usage:

val reporter = ProgressReporter { println(it) }
    .reduceToInterval(0.2..0.4)

reporter.report(loading(0.1)) // prints 'Loading(22%)'

Parameters

  • treatDoneAs: When a Progress.Done is received, it will be treated as if that value was received.

  • treatUnquantifiedAs: When a Progress.Loading.Unquantified is received, it will be treated as if that value was received.

report

abstract fun report(progress: Progress)

Reports that the current task has reached progress.