Logo Orsak

Time Module

Effects for reading the time, and waiting, through an ITimeProvider.

Functions and values

Function or value Description

delay delay

Full Usage: delay delay

Parameters:
Returns: Effect<'a, unit, 'b>
Type parameters: 'a, 'b (requires :> Orsak.ITimeProvider)

An effect that waits for delay on the environment's clock, so that a fake clock in tests decides when it ends. When the environment is also an ICancellationProvider, cancelling its source ends the wait early, with a TaskCanceledException. Not on Fable, where an environment can't be tested for an interface it may implement: there the wait is the clock's Delay, and isn't ended by the environment's source.

delay : TimeSpan

The time to wait.

Returns: Effect<'a, unit, 'b>
Example

 let poll () = eff {
     while true do
         do! Queue.drain ()
         do! Time.delay (TimeSpan.FromSeconds 5.0)
 }
val poll: unit -> 'a

utcNow ()

Full Usage: utcNow ()

Parameters:
    () : unit

Returns: Effect<'a, DateTimeOffset, 'b>
Type parameters: 'a, 'b (requires :> Orsak.ITimeProvider)

An effect that reads the current UTC time from the environment's clock.

() : unit
Returns: Effect<'a, DateTimeOffset, 'b>
Example

 let isExpired (expires: DateTimeOffset) = eff {
     let! now = Time.utcNow ()
     return now > expires
 }
val isExpired: expires: 'a -> 'b
val expires: 'a

Type something to start searching.