Skip to content

Commit

Permalink
Allow the reference clock to be adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyicker committed Aug 7, 2023
1 parent bceb2f5 commit 9ae85f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tidal.networktime

import kotlin.time.Duration

interface ReadableClock {
val time: Duration
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tidal.networktime

import kotlin.time.Duration

interface WriteableClock : ReadableClock {
override var time: Duration
}

0 comments on commit 9ae85f3

Please sign in to comment.