Commit 89869522 by patpat

优化TimerHelper

parent b4333db8
......@@ -48,16 +48,22 @@ object TimerHelper {
}
fun loop(task: LoopTask, period: Long): Long {
return loop(task, period, -1)
return loop(task, period, -1, 0)
}
fun loop(task: LoopTask, period: Long, times: Int): Long {
return loop({ id: Long, isLastTime: Boolean ->
task.run(id, isLastTime)
}, period, times)
}, period, times, 0)
}
fun loop(runnable: (id: Long, isLastTime: Boolean) -> Unit, period: Long, times: Int = -1): Long {
fun loop(task: LoopTask, period: Long, times: Int, delay: Long): Long {
return loop({ id: Long, isLastTime: Boolean ->
task.run(id, isLastTime)
}, period, times, delay)
}
fun loop(runnable: (id: Long, isLastTime: Boolean) -> Unit, period: Long, times: Int = -1, delay: Long = 0): Long {
val id = mId
mFutureList.put(id, mScheduledExecutorService.scheduleAtFixedRate(object: Runnable {
var vTimes = 0
......@@ -75,7 +81,7 @@ object TimerHelper {
Log.w(TAG, "loop id: $id times: $vTimes error: ${e.message}")
}
}
}, 0, period, TimeUnit.MILLISECONDS))
}, delay, period, TimeUnit.MILLISECONDS))
return id
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment