Updated the code documentation.
Some checks failed
/ Build and Release Library (push) Failing after 1m3s
Some checks failed
/ Build and Release Library (push) Failing after 1m3s
This commit is contained in:
parent
ab8ee3b24d
commit
dd415c957a
1 changed files with 27 additions and 0 deletions
|
@ -75,15 +75,42 @@ object MonotonicProvider:
|
|||
final class SystemProvider[F[_]: Sync] extends MonotonicProvider[F]:
|
||||
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 (
|
||||
ticks: Ref[F, Long]
|
||||
) extends MonotonicProvider[F]:
|
||||
/**
|
||||
* @return The current tick count.
|
||||
*/
|
||||
override def monotonic(): F[Long] = ticks.get
|
||||
|
||||
/**
|
||||
* Increment the tick count by 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)
|
||||
|
||||
/**
|
||||
* Reset the tick count to 0.
|
||||
*/
|
||||
def reset(): F[Unit] = ticks.set(0)
|
||||
|
||||
object ManualTickProvider:
|
||||
|
|
Loading…
Add table
Reference in a new issue