A simple replacement for the Java clock and scheduler.
In Gradle, install the ForkHandles BOM and then this module in the dependency block:
implementation(platform("dev.forkhandles:forkhandles-bom:X.Y.Z"))
implementation("dev.forkhandles:time4k")
The Java Clock
is an abstract class, which is a pain. Time4k represents the clock as a simple typealias:
typealias TimeSource = () -> Instant
The library also provides a DeterministicScheduler which is a drop-in test replacement for using a ScheduledExecutorService
. You can control time and make the scheduler move forward in a controlled manner.