mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-28 08:21:02 +00:00
Initial commit
This commit is contained in:
27
app/src/main/java/ani/dantotsu/others/ResettableTimer.kt
Normal file
27
app/src/main/java/ani/dantotsu/others/ResettableTimer.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package ani.dantotsu.others
|
||||
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.*
|
||||
|
||||
class ResettableTimer {
|
||||
var resetLock = AtomicBoolean(false)
|
||||
var timer = Timer()
|
||||
fun reset(timerTask: TimerTask, delay: Long) {
|
||||
if (!resetLock.getAndSet(true)) {
|
||||
timer.cancel()
|
||||
timer.purge()
|
||||
timer = Timer()
|
||||
timer.schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
if (!resetLock.getAndSet(true)) {
|
||||
timerTask.run()
|
||||
timer.cancel()
|
||||
timer.purge()
|
||||
resetLock.set(false)
|
||||
}
|
||||
}
|
||||
}, delay)
|
||||
resetLock.set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user