-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
56 additions
and
24 deletions.
There are no files selected for viewing
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
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
11 changes: 0 additions & 11 deletions
11
library/src/commonMain/kotlin/com/tidal/networktime/internal/StartSyncRunnable.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../networktime/internal/StopSyncRunnable.kt → ...tidal/networktime/internal/SyncDisable.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
21 changes: 21 additions & 0 deletions
21
library/src/commonMain/kotlin/com/tidal/networktime/internal/SyncEnable.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,21 @@ | ||
package com.tidal.networktime.internal | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
import kotlin.time.Duration | ||
|
||
internal class SyncEnable( | ||
private val mutableState: MutableState, | ||
private val coroutineScope: CoroutineScope, | ||
private val syncDispatcher: CoroutineDispatcher, | ||
private val syncInterval: Duration, | ||
) : () -> Unit { | ||
override operator fun invoke() = with(mutableState) { | ||
val job = job | ||
if (job != null && !job.isCancelled) { | ||
return | ||
} | ||
this.job = coroutineScope.launch(syncDispatcher) { SyncPeriodic(syncInterval)() } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
library/src/commonMain/kotlin/com/tidal/networktime/internal/SyncPeriodic.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,13 @@ | ||
package com.tidal.networktime.internal | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlin.time.Duration | ||
|
||
internal class SyncPeriodic(private val syncInterval: Duration) { | ||
suspend operator fun invoke() { | ||
while (true) { | ||
SyncSingular()() | ||
delay(syncInterval) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
library/src/commonMain/kotlin/com/tidal/networktime/internal/SyncSingular.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,7 @@ | ||
package com.tidal.networktime.internal | ||
|
||
internal class SyncSingular { | ||
suspend operator fun invoke() { | ||
TODO() | ||
} | ||
} |