Updated the code documentation.
Some checks failed
/ Build and Release Library (push) Failing after 1m3s

This commit is contained in:
Pat Garrity 2024-09-10 21:04:50 -05:00
parent ab8ee3b24d
commit dd415c957a
Signed by: pfm
GPG key ID: 5CA5D21BAB7F3A76

View file

@ -75,15 +75,42 @@ 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
* to directly increment/set a tick count, where each tick corresponds to one
* nanosecond of elapsed time.
*
* Use `ManualTickProvider.initialize[F]` to instantiate this class:
*
* {{{
* val program: IO[ManualTickProvider[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 The current tick count.
*/
override def monotonic(): F[Long] = ticks.get override def monotonic(): F[Long] = ticks.get
/**
* 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.
*
* @param newTickCount The new tick count value.
* @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.
*/
def reset(): F[Unit] = ticks.set(0) def reset(): F[Unit] = ticks.set(0)
object ManualTickProvider: object ManualTickProvider: