summaryrefslogtreecommitdiff
path: root/opendc-common/src/main/kotlin/org
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-09 17:25:59 +0000
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-11-13 15:24:47 +0000
commit7a4b2c45a9926de59754b1d7219159656eea6e6d (patch)
tree4cf2cd842ec046128401a5b15bd42d86505422c6 /opendc-common/src/main/kotlin/org
parentc22d744464f91eaa5f1aabee408351e864f36f1d (diff)
refactor: Use InstantSource as time source
This change updates the modules of OpenDC to always accept the `InstantSource` interface as source of time. Previously we used `java.time.Clock`, but this class is bound to a time zone which does not make sense for our use-cases. Since `java.time.Clock` implements `java.time.InstantSource`, it can be used in places that require an `InstantSource` as parameter. Conversion from `InstantSource` to `Clock` is also possible by invoking `InstantSource#withZone`.
Diffstat (limited to 'opendc-common/src/main/kotlin/org')
-rw-r--r--opendc-common/src/main/kotlin/org/opendc/common/util/Pacer.kt4
-rw-r--r--opendc-common/src/main/kotlin/org/opendc/common/util/TimerScheduler.kt4
2 files changed, 4 insertions, 4 deletions
diff --git a/opendc-common/src/main/kotlin/org/opendc/common/util/Pacer.kt b/opendc-common/src/main/kotlin/org/opendc/common/util/Pacer.kt
index edf607d2..b6141db1 100644
--- a/opendc-common/src/main/kotlin/org/opendc/common/util/Pacer.kt
+++ b/opendc-common/src/main/kotlin/org/opendc/common/util/Pacer.kt
@@ -26,7 +26,7 @@ import kotlinx.coroutines.Delay
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.InternalCoroutinesApi
import java.lang.Runnable
-import java.time.Clock
+import java.time.InstantSource
import kotlin.coroutines.ContinuationInterceptor
import kotlin.coroutines.CoroutineContext
@@ -40,7 +40,7 @@ import kotlin.coroutines.CoroutineContext
*/
public class Pacer(
private val context: CoroutineContext,
- private val clock: Clock,
+ private val clock: InstantSource,
private val quantum: Long,
private val process: (Long) -> Unit
) {
diff --git a/opendc-common/src/main/kotlin/org/opendc/common/util/TimerScheduler.kt b/opendc-common/src/main/kotlin/org/opendc/common/util/TimerScheduler.kt
index 44d6010f..864512d3 100644
--- a/opendc-common/src/main/kotlin/org/opendc/common/util/TimerScheduler.kt
+++ b/opendc-common/src/main/kotlin/org/opendc/common/util/TimerScheduler.kt
@@ -25,7 +25,7 @@ package org.opendc.common.util
import kotlinx.coroutines.Delay
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.InternalCoroutinesApi
-import java.time.Clock
+import java.time.InstantSource
import java.util.ArrayDeque
import java.util.PriorityQueue
import kotlin.coroutines.ContinuationInterceptor
@@ -37,7 +37,7 @@ import kotlin.coroutines.CoroutineContext
* @param context The [CoroutineContext] to run the tasks with.
* @param clock The clock to keep track of the time.
*/
-public class TimerScheduler<T>(private val context: CoroutineContext, private val clock: Clock) {
+public class TimerScheduler<T>(private val context: CoroutineContext, private val clock: InstantSource) {
/**
* The [Delay] instance that provides scheduled execution of [Runnable]s.
*/