Skip to content

Instantly share code, notes, and snippets.

@rommansabbir
Created May 4, 2021 16:28
Show Gist options
  • Save rommansabbir/692ab5356adaf38fd4a8be6428bdb3bb to your computer and use it in GitHub Desktop.
Save rommansabbir/692ab5356adaf38fd4a8be6428bdb3bb to your computer and use it in GitHub Desktop.
var handlerDelayTimer: Timer = Timer()
inline fun handlerPost(crossinline onSuccess: () -> Unit) {
Handler(Looper.getMainLooper()).post {
onSuccess.invoke()
}
}
inline fun handlerPostDelayed(delay: Long, crossinline onSuccess: () -> Unit) {
handlerDelayTimer.cancel()
handlerDelayTimer = Timer()
handlerDelayTimer.schedule(object : TimerTask() {
override fun run() {
Handler(Looper.getMainLooper()).post {
onSuccess.invoke()
}
}
}, delay)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment