This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from boswelja/wearos-status-improvements
WearOS flow improvements
- Loading branch information
Showing
2 changed files
with
77 additions
and
68 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
wearos/src/main/kotlin/com/boswelja/watchconnection/wearos/Helpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.boswelja.watchconnection.wearos | ||
|
||
import kotlinx.coroutines.delay | ||
|
||
/** | ||
* Schedule a suspendable code block to be executed at a regular interval. | ||
* @param interval The interval in milliseconds to execute the code block after. Must be greater | ||
* than 0. | ||
* @param initialDelay The initial delay in milliseconds before first execution. Values less than or | ||
* equal to 0 are ignored. | ||
* @param action The suspendable code block to be executed. | ||
*/ | ||
internal suspend fun repeating( | ||
interval: Long, | ||
initialDelay: Long = 0, | ||
action: suspend () -> Unit | ||
) { | ||
if (interval <= 0) throw IllegalArgumentException("interval must be greater than 0") | ||
if (initialDelay > 0) delay(initialDelay) | ||
while (true) { | ||
action() | ||
delay(interval) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters