This commit is contained in:
parent
dd415c957a
commit
1221fc85e8
1 changed files with 25 additions and 27 deletions
|
@ -75,42 +75,40 @@ object MonotonicProvider:
|
||||||
final class SystemProvider[F[_]: Sync] extends MonotonicProvider[F]:
|
final class SystemProvider[F[_]: Sync] extends MonotonicProvider[F]:
|
||||||
override def monotonic(): F[Long] = Sync[F].delay(System.nanoTime())
|
override def monotonic(): F[Long] = Sync[F].delay(System.nanoTime())
|
||||||
|
|
||||||
/**
|
/** Manual implementation of the [[MonotonicProvider]] that allows the caller
|
||||||
* Manual implementation of the [[MonotonicProvider]] that allows the caller
|
* to directly increment/set a tick count, where each tick corresponds to one
|
||||||
* to directly increment/set a tick count, where each tick corresponds to one
|
* nanosecond of elapsed time.
|
||||||
* nanosecond of elapsed time.
|
*
|
||||||
*
|
* Use `ManualTickProvider.initialize[F]` to instantiate this class:
|
||||||
* Use `ManualTickProvider.initialize[F]` to instantiate this class:
|
*
|
||||||
*
|
* {{{
|
||||||
* {{{
|
* val program: IO[ManualTickProvider[IO]] =
|
||||||
* val program: IO[ManualTickProvider[IO]] =
|
* ManualTickProvider.initialize[IO]
|
||||||
* ManualTickProvider.initialize[IO]
|
* }}}
|
||||||
* }}}
|
*/
|
||||||
*/
|
|
||||||
final class ManualTickProvider[F[_]: Sync] private (
|
final class ManualTickProvider[F[_]: Sync] private (
|
||||||
ticks: Ref[F, Long]
|
ticks: Ref[F, Long]
|
||||||
) extends MonotonicProvider[F]:
|
) extends MonotonicProvider[F]:
|
||||||
/**
|
/** @return
|
||||||
* @return The current tick count.
|
* The current tick count.
|
||||||
*/
|
*/
|
||||||
override def monotonic(): F[Long] = ticks.get
|
override def monotonic(): F[Long] = ticks.get
|
||||||
|
|
||||||
/**
|
/** Increment the tick count by 1.
|
||||||
* Increment the tick count by 1.
|
*/
|
||||||
*/
|
|
||||||
def tick(): F[Unit] = ticks.update(_ + 1)
|
def tick(): F[Unit] = ticks.update(_ + 1)
|
||||||
|
|
||||||
/**
|
/** Set the tick count to a specific value.
|
||||||
* Set the tick count to a specific value.
|
*
|
||||||
*
|
* @param newTickCount
|
||||||
* @param newTickCount The new tick count value.
|
* The new tick count value.
|
||||||
* @return Side-effect.
|
* @return
|
||||||
*/
|
* Side-effect.
|
||||||
|
*/
|
||||||
def set(newTickCount: Long): F[Unit] = ticks.set(newTickCount)
|
def set(newTickCount: Long): F[Unit] = ticks.set(newTickCount)
|
||||||
|
|
||||||
/**
|
/** Reset the tick count to 0.
|
||||||
* Reset the tick count to 0.
|
*/
|
||||||
*/
|
|
||||||
def reset(): F[Unit] = ticks.set(0)
|
def reset(): F[Unit] = ticks.set(0)
|
||||||
|
|
||||||
object ManualTickProvider:
|
object ManualTickProvider:
|
||||||
|
|
Loading…
Add table
Reference in a new issue