Skip to content

LazyWorker is a helper class for doing tasks delayed. Such as checking inputs which require network operations and should not been done after each key down.

License

Notifications You must be signed in to change notification settings

rekire/LazyWorker

Repository files navigation

LazyWorker Maven Central

LazyWorker is a helper class for doing tasks delayed. Such as checking inputs which require network operations and should not been done after each key down.

Setup (gradle based)

Edit your build.gradle and add this line to your dependencies:

implementation 'eu.rekisoft.android:lazyworker:2.0.4'

It should look something like this:

implementation {
    // other dependencies comes here
    implementation 'eu.rekisoft.android:lazyworker:2.0.4'
}

Example

Here is a sample for implementing a lifecycle aware countdown timer in Kotlin:

val countdown = LazyWorker.createLifeCycleAwareJob(viewLifecycleOwner.lifecycle) {
    val left = expiresAt - System.currentTimeMillis()
    val remaining = "%d:%02d".format(
        TimeUnit.MILLISECONDS.toMinutes(left),
        TimeUnit.MILLISECONDS.toSeconds(left % 60000)
    )
    println(remaining)
    if (expiresAt > System.currentTimeMillis()) {
        doLater(1000)
    } else {
        println("Time expired")
    }
}

// Start timer
countdown.doNow()

About

LazyWorker is a helper class for doing tasks delayed. Such as checking inputs which require network operations and should not been done after each key down.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages