Skip to content

Commit

Permalink
Add defensive checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhuparas committed Apr 10, 2021
1 parent 02baf67 commit 9282d12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions every/src/main/java/com/paras/every/Every.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ internal class Every(
init {
lifecycleOwner.lifecycle.addObserver(this)
job = CoroutineScope(Dispatchers.Main).launch {
if (sleepTimeInMillis <= 0) {
return@launch
}

while (isActive) {
val timeTaken = measureTimeMillis { action(elapsedTime) }
delay(sleepTimeInMillis)
Expand Down
4 changes: 4 additions & 0 deletions every/src/main/java/com/paras/every/after/After.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ internal class After(
init {
lifecycleOwner.lifecycle.addObserver(this)
job = CoroutineScope(Dispatchers.Main).launch {
if (timeInMillis <= 0) {
return@launch
}

delay(timeInMillis)
ensureActive()
action()
Expand Down

0 comments on commit 9282d12

Please sign in to comment.