diff --git a/library/src/commonMain/kotlin/com/tidal/networktime/ReadableClock.kt b/library/src/commonMain/kotlin/com/tidal/networktime/ReadableClock.kt new file mode 100644 index 00000000..7b37d6c8 --- /dev/null +++ b/library/src/commonMain/kotlin/com/tidal/networktime/ReadableClock.kt @@ -0,0 +1,7 @@ +package com.tidal.networktime + +import kotlin.time.Duration + +interface ReadableClock { + val time: Duration +} diff --git a/library/src/commonMain/kotlin/com/tidal/networktime/SNTPClient.kt b/library/src/commonMain/kotlin/com/tidal/networktime/SNTPClient.kt index 9a362e31..cfea16ff 100644 --- a/library/src/commonMain/kotlin/com/tidal/networktime/SNTPClient.kt +++ b/library/src/commonMain/kotlin/com/tidal/networktime/SNTPClient.kt @@ -10,15 +10,16 @@ import kotlin.time.Duration.Companion.seconds * [ntpServers] to obtain information about their provided time. * * @param ntpServers Representation of supported unicast NTP sources. - * @param referenceClock A provider of UNIX time, used to calculate timing differences with the - * information obtained from [ntpServers]. + * @param referenceClock A provider of UNIX time used to calculate timing differences with the + * information obtained from [ntpServers]. May optionally implement [WriteableClock] to be adjusted + * on every synchronization with the calculated time difference. * @param coroutineScope The scope where synchronization will run on. * @param syncInterval The amount of time to wait between a sync finishing and the next one being * started. */ class SNTPClient( vararg val ntpServers: NTPServer, - val referenceClock: () -> Duration, + val referenceClock: ReadableClock, val coroutineScope: CoroutineScope = GlobalScope, val syncInterval: Duration = 64.seconds, ) { diff --git a/library/src/commonMain/kotlin/com/tidal/networktime/WriteableClock.kt b/library/src/commonMain/kotlin/com/tidal/networktime/WriteableClock.kt new file mode 100644 index 00000000..6aaa5f09 --- /dev/null +++ b/library/src/commonMain/kotlin/com/tidal/networktime/WriteableClock.kt @@ -0,0 +1,7 @@ +package com.tidal.networktime + +import kotlin.time.Duration + +interface WriteableClock : ReadableClock { + override var time: Duration +}