Commit ca258f22 by patpat

优化代码

parent 88210ec0
......@@ -76,7 +76,7 @@ class WifiAction private constructor() : Action(ActionEnum.CONFIG_WIFI.name) {
}
EventBus.getDefault().post(WifiStateEvent(30, "正在连接Wifi"))
TimerHelper.loop({ id, isLastTime ->
TimerHelper.loop({ _, isLastTime ->
if (isLastTime) {
if (state == State.STARTED) {
state = State.FAIL
......
......@@ -41,7 +41,7 @@ object TimerHelper {
try {
runnable()
} catch (e: Exception) {
Log.w(TAG, "timeout id: $id times error: ${e.message}")
Log.w(TAG, "timeout id: $id error: ${e.message}")
}
}, time, TimeUnit.MILLISECONDS))
return id
......@@ -60,7 +60,7 @@ object TimerHelper {
fun loop(runnable: (id: Long, isLastTime: Boolean) -> Boolean, period: Long, times: Int = -1): Long {
val id = mId
mFutureList.put(id, mScheduledExecutorService.scheduleWithFixedDelay(object: Runnable {
mFutureList.put(id, mScheduledExecutorService.scheduleAtFixedRate(object: Runnable {
var vTimes = 0
override fun run() {
if (times >= 0) {
......@@ -75,7 +75,7 @@ object TimerHelper {
cancel(id)
}
} catch (e: Exception) {
Log.w(TAG, "loop id: $id times error: ${e.message}")
Log.w(TAG, "loop id: $id times: $vTimes error: ${e.message}")
}
}
}, 0, period, TimeUnit.MILLISECONDS))
......
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