Created
May 4, 2021 16:28
-
-
Save rommansabbir/692ab5356adaf38fd4a8be6428bdb3bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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