We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de435ea commit e1f0173Copy full SHA for e1f0173
interval/src/main/java/com/drake/interval/Interval.kt
@@ -32,6 +32,7 @@ import kotlinx.coroutines.channels.ticker
32
import java.io.Closeable
33
import java.io.Serializable
34
import java.util.concurrent.TimeUnit
35
+import kotlin.math.max
36
37
/**
38
* 创建一个轮询器
@@ -170,7 +171,8 @@ open class Interval @JvmOverloads constructor(
170
171
if (state != IntervalStatus.STATE_ACTIVE) return
172
scope?.cancel()
173
state = IntervalStatus.STATE_PAUSE
- delay = SystemClock.elapsedRealtime() - countTime
174
+ // 一个计时单位的总时间减去距离上次计时已过的时间,等于resume时需要delay的时间
175
+ delay = max(unit.toMillis(period) - (SystemClock.elapsedRealtime() - countTime), 0L)
176
}
177
178
0 commit comments