https://kotlinlang.org logo
#feed
Title
# feed
c

CLOVIS

09/21/2023, 7:30 AM
Pedestal Progress 2.0.0 is out! Pedestal Progress is a multiplatform micro-library to represent progress indicators and other types of in-between states for asynchronous operations. It is based on three basic values:
Copy code
println(done())       // Done
println(loading())    // Loading
println(loading(0.2)) // Loading(20%)
Custom implementations can be created to add any other kind of information (ETAs, bandwidth, transfer speed…). Progress is meant to provide a common standard, allowing its use both in UI libraries and HTTP/API libraries to seamlessly share information without being aware of each other. Progress information can be reported to the caller in a variety of ways; for example, with context receivers…
Copy code
context(ProgressReporter)
fun foo() {
    report(loading(0.0)) // reports 0% loading to the caller…
    doSomeOperation()
    report(loading(0.5))
    otherOperation()
    report(done())
}

fun main() {
    val reporter = ProgressReporter(::println) // do anything you want: log it, update the UI…
    with(reporter) { foo() }
}
…or via the coroutine context:
Copy code
suspend fun foo() {
    report(loading(0.0))
    doSomeOperation()
    report(loading(0.5))
    otherOperation()
    report(done())
}

suspend fun main() {
    val reporter = ProgressReporter(::println)
    withContext(reporter.asCoroutineContext()) { foo() }
}
Through implicit embedding in the coroutine context, it is possible to introduce this library without changing function signatures, directly in the functions that would benefit the most. Since the caller must opt-in to event generation by providing a reporter, it can be used in libraries safely. Learn more: DocumentationMaven CentralRepository • or ask questions in this thread!
K 5
👍 1
👍🏾 1
🎉 1
2 Views