View Source Clock protocol (Clock v0.1.0)

A simple clock protocol for time traveling in tests.

In your code, hold onto a clock struct and use the protocol for all things time related.

clock = %Clock.RealClock{}
...
now = Clock.now(clock)

In tests, make sure the clock struct is a FakeClock and use it to time travel.

clock = %Clock.FakeClock{}
...
now = Clock.now(clock)
Clock.FakeClock.travel(clock, 60_000)
one_minute_later = Clock.now(clock)

Summary

Types

t()

All the types that implement this protocol.

Types

@type t() :: term()

All the types that implement this protocol.

@type tref() :: term()

Functions

@spec cancel(t(), tref()) :: :ok
@spec now(t()) :: DateTime.t()
Link to this function

send_after(clock, destination, message, duration_in_ms)

View Source
@spec send_after(t(), pid() | atom(), term(), non_neg_integer()) :: tref()
Link to this function

send_interval(clock, destination, message, interval_in_ms)

View Source
@spec send_interval(t(), pid() | atom(), term(), non_neg_integer()) :: tref()