Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptIClock supplies UtcNow(), monotonic Elapsed() and cancellable Sleep(). Clock.now and timed Flow operations
read the clock installed in the current runtime scope. An application environment does not need a clock field or
interface. Clock.live is the default; Flow.withClock clock overrides it for a flow and its descendants.
Show page setup
open System
open Axial
open Axial
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actuallet expiresWithin (window: TimeSpan) (expiry: DateTimeOffset) : Flow<'env, Never, bool> =
Clock.now |> Flow.map (fun now -> expiry - now <= window)
expiresWithin: TimeSpan -> DateTimeOffset -> Flow<'env,Never,bool>window: TimeSpanSystem.TimeSpanRepresents a time interval.
expiry: DateTimeOffsetSystem.DateTimeOffsetRepresents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).
Axial.Flow`3envAxial.NeverRepresents an error channel that cannot occur.
boolAn abbreviation for the CLI type . Basic Types
Axial.ClockHelpers for the clock service.
now: Flow<'env,'error,DateTimeOffset>Reads the current UTC timestamp from an explicit clock service.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowmap: ('value -> 'next) -> Flow<'env,'error,'value> -> Flow<'env,'error,'next>Transforms the successful value of a flow. If the source fails, the is not executed. The original failure cause is preserved, including typed failures, interruption, and defects. Use map for pure value transformations after an effect has succeeded. A function of type 'value -> 'next to transform the successful value. The source flow of type to transform. A new with the transformed success value of type 'next. let flow = Flow.succeed 1 |> Flow.map (fun x -> x + 1)
now: DateTimeOffset(-): ^T1 -> ^T2 -> ^T3Overloaded subtraction operator The first parameter. The second parameter. The result of the operation. 10 - 2 // Evaluates to 8
(<=): 'T -> 'T -> boolStructural less-than-or-equal comparison The first parameter. The second parameter. The result of the comparison. 5 <= 1 // Evaluates to false 5 <= 5 // Evaluates to true [1; 5] <= [1; 6] // Evaluates to true
Requires & types
Requires: open Axial; open System (packages: Axial)val expiresWithin: TimeSpan -> DateTimeOffset -> Flow<'env,Never,bool>Read a chosen instant
Clock.fromValue creates a manual clock starting at a chosen instant:
> open System;;
> open Axial;;
> open Axial;;
> let atNoon () = Clock.fromValue (DateTimeOffset(2026, 1, 1, 12, 0, 0, TimeSpan.Zero));;
> (Clock.now : Flow<unit, Never, DateTimeOffset>) |> Flow.map _.Hour |> Flow.withClock (atNoon ()) |> Flow.run ();;
> (Clock.utcDateTime : Flow<unit, Never, DateTime>) |> Flow.map _.Kind |> Flow.withClock (atNoon ()) |> Flow.run ();;
> (Clock.unixTimeSeconds : Flow<unit, Never, int64>) |> Flow.withClock (atNoon ()) |> Flow.run ();;
> (Clock.unixTimeMilliseconds : Flow<unit, Never, int64>) |> Flow.withClock (atNoon ()) |> Flow.run ();;val it: Exit<int,Never> = Success 12
val it: Exit<DateTimeKind,Never> = Success Utc
val it: Exit<int64,Never> = Success 1767268800L
val it: Exit<int64,Never> = Success 1767268800000LSystemAxialatNoon: unit -> ManualClockAxial.ClockHelpers for the clock service.
fromValue: DateTimeOffset -> ManualClockCreates a manual clock starting at the supplied instant. Sleeps require explicit advancement.
``.ctor``: int * int * int * int * int * int * TimeSpan -> unitInitializes a new instance of the structure using the specified year, month, day, hour, minute, second, and offset. The year (1 through 9999). The month (1 through 12). The day (1 through the number of days in ). The hours (0 through 23). The minutes (0 through 59). The seconds (0 through 59). The time's offset from Coordinated Universal Time (UTC). does not represent whole minutes. is less than one or greater than 9999. -or- is less than one or greater than 12. -or- is less than one or greater than the number of days in . -or- is less than zero or greater than 23. -or- is less than 0 or greater than 59. -or- is less than 0 or greater than 59. -or- is less than -14 hours or greater than 14 hours. -or- The property is earlier than or later than .
System.TimeSpanRepresents a time interval.
Zero: TimeSpanRepresents the zero value. This field is read-only.
now: Flow<'env,'error,DateTimeOffset>Reads the current UTC timestamp from an explicit clock service.
Axial.Flow`3unitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
Axial.NeverRepresents an error channel that cannot occur.
System.DateTimeOffsetRepresents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowmap: ('value -> 'next) -> Flow<'env,'error,'value> -> Flow<'env,'error,'next>Transforms the successful value of a flow. If the source fails, the is not executed. The original failure cause is preserved, including typed failures, interruption, and defects. Use map for pure value transformations after an effect has succeeded. A function of type 'value -> 'next to transform the successful value. The source flow of type to transform. A new with the transformed success value of type 'next. let flow = Flow.succeed 1 |> Flow.map (fun x -> x + 1)
_arg1: DateTimeOffsetHour: intGets the hour component of the time represented by the current object. The hour component of the current object. This property uses a 24-hour clock; the value ranges from 0 to 23.
withClock: IClock -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Overrides the clock within this flow and its descendants.
run: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
utcDateTime: Flow<'env,'error,DateTime>Reads the current UTC date/time from an explicit clock service.
System.DateTimeRepresents an instant in time, typically expressed as a date and time of day.
_arg1: DateTimeKind: DateTimeKindGets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither. One of the enumeration values that indicates what the current time represents. The default is .
unixTimeSeconds: Flow<'env,'error,int64>Reads the current Unix timestamp in seconds from an explicit clock service.
int64An abbreviation for the CLI type . Basic Types
unixTimeMilliseconds: Flow<'env,'error,int64>Reads the current Unix timestamp in milliseconds from an explicit clock service.
These readers do not introduce a typed error. Clock.service returns the installed IClock when an interop
boundary needs the service itself.
Measure durations
Use Clock.elapsed differences or Clock.timed, not wall-clock subtraction: UTC can jump when adjusted.
let timedReport : Flow<unit, Never, string> =
flow {
let! report, took = Flow.ok "report" |> Clock.timed
do! Log.info $"report built in {took.TotalMilliseconds:F0} ms"
return report
}
timedReport: Flow<unit,Never,string>Axial.Flow`3unitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
Axial.NeverRepresents an error channel that cannot occur.
stringAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
report: stringtook: TimeSpanAxial.Flowok: 'value -> Flow<'env,'error,'value>Creates a successful synchronous flow. The value to wrap in a successful flow. A flow that always succeeds with the provided value.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.ClockHelpers for the clock service.
timed: Flow<'env,'error,'value> -> Flow<'env,'error,('value * TimeSpan)>Runs a flow and returns its value together with how long it took. Measured with the clock's monotonic timer, so the duration is unaffected by system clock adjustments and is deterministic under a test clock. Failures propagate unchanged and are not timed. The flow to measure. let! report, took = buildReport |> Clock.timed
Axial.LogHelpers for the logging service.
info: string -> Flow<'env,'error,unit>Writes an informational message to the installed log sink.
Requires & types
Requires: open Axial (packages: Axial)val timedReport: Flow<unit,Never,string>let log = Log.memory ()
timedReport
|> Flow.withClock (Clock.fromValue DateTimeOffset.UnixEpoch)
|> Flow.withLogSink log
|> Flow.run ()
|> shouldEqual (Exit.Success "report")
log.Entries |> Seq.map _.Message |> Seq.toList |> shouldEqual ["report built in 0 ms"]
log: TestLogAxial.LogHelpers for the logging service.
memory: unit -> TestLogtimedReport: Flow<unit,Never,string>(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.FlowwithClock: IClock -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Overrides the clock within this flow and its descendants.
Axial.ClockHelpers for the clock service.
fromValue: DateTimeOffset -> ManualClockCreates a manual clock starting at the supplied instant. Sleeps require explicit advancement.
System.DateTimeOffsetRepresents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC).
UnixEpoch: DateTimeOffsetwithLogSink: ILogSink -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Replaces the log destination within this flow and its descendants.
run: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
shouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Entries: Collections.Generic.IReadOnlyList<LogEntry>The recorded entries, in the order they were written.
Microsoft.FSharp.Collections.SeqModuleContains operations for working with values of type .
map: ('T -> 'U) -> 'T seq -> 'U seqBuilds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The given function will be applied as elements are demanded using the MoveNext method on enumerators retrieved from the object. The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently. A function to transform items from the input sequence. The input sequence. The result sequence. Thrown when the input sequence is null. let inputs = ["a"; "bbb"; "cc"] inputs |> Seq.map (fun x -> x.Length) Evaluates to a sequence yielding the same results as seq { 1; 3; 2 }
_arg1: LogEntryMessage: stringtoList: 'T seq -> 'T listBuilds a list from the given collection. The input sequence. The result list. Thrown when the input sequence is null. let inputs = seq { 1; 2; 5 } inputs |> Seq.toList Evaluates to [ 1; 2; 5 ].
Requires & types
Requires: open Axial; open System (packages: Axial)val log: TestLogA manual clock reports zero elapsed duration only while nobody advances it. Clock.fromValue instant returns a
ManualClock, on .NET and Fable. Sleep does not throw: it waits until the test advances far enough. An unadvanced timed test can therefore remain suspended indefinitely.
Step time explicitly
Flow.runTest installs an epoch manual clock, recording log, seeded random and sequential GUIDs. Use
Flow.runTestWith when the test needs those instances. Await facts such as sleeper registration before advancing,
not a wall-clock pause or a guess that the scheduler is idle:
let platform = TestPlatform.create ()
let registered =
match Deferred.make<unit, Never, unit, _> () |> Flow.run () |> Exit.toResult with
| Ok deferred -> deferred
| Error never -> Never.absurd never
let clock = platform.Clock :> IClock
let notifying =
{ new IClock with
member _.UtcNow() = clock.UtcNow()
member _.Elapsed() = clock.Elapsed()
member _.Sleep(delay, token) =
let pending = clock.Sleep(delay, token)
Deferred.succeedNow () registered |> ignore
pending }
let stepped: Flow<unit, Never, int> = flow {
let! child = Flow.sleep (TimeSpan.FromSeconds 5.) |> Flow.withClock notifying |> Flow.fork
do! Deferred.await registered
do! TestClock.advance (TimeSpan.FromSeconds 4.)
let! waiting = TestClock.sleepers
do! TestClock.advance (TimeSpan.FromSeconds 1.)
do! Fiber.join child
return waiting
}
stepped |> Flow.runTestWith platform () |> shouldEqual (Exit.Success 1)
platform: TestPlatformAxial.TestPlatformA recorded read identifies the runtime service member and the fiber which read it.
create: unit -> TestPlatformregistered: Deferred<Never,unit>Axial.DeferredModuleFlow-native helpers for one-shot typed coordination.
make: unit -> Flow<'env,'workflowError,Deferred<'error,'value>>Creates an empty deferred value. Creating a deferred never fails, so the flow's error type, the last type parameter, is independent of the deferred's.
unitThe type 'unit', which has only one value "()". This value is special and always uses the representation 'null'. Basic Types
Axial.NeverRepresents an error channel that cannot occur.
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
Axial.Flowrun: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
Axial.ExittoResult: Exit<'v,'e> -> Result<'v,'e>Converts an exit outcome to a standard F# Result. The exit outcome to convert. A Result representing the successful value or the domain failure. Re-throws the original exception if the exit was Cause.Die. Throws if the exit was Cause.Interrupt.
OkRepresents an OK or a Successful result. The code succeeded with a value of 'T.
deferred: Deferred<Never,unit>ErrorRepresents an Error or a Failure. The code failed with a value of 'TError representing what went wrong.
never: NeverAxial.NeverModuleUses the fact that a value cannot exist.
absurd: Never -> 'aConverts a Never to any type. No Never value exists, so this function is never called with one. Pass it where a mapping from the error channel is required, to widen a flow, layer, cause, or exit that cannot fail into one with a real error type: Exit.mapError Never.absurd. Flow.widenError and Layer.widenError cover the common cases. let exit : Exit<int, string> = Exit.Success 1 |> Exit.mapError Never.absurd
clock: IClockClock: ManualClockAxial.IClockSupplies wall time, monotonic time, and cancellable delays from one source. Wall time is for timestamps. Use differences between Elapsed readings for durations.
notifying: IClock_: IClockUtcNow: unit -> DateTimeOffsetElapsed: unit -> TimeSpanSleep: TimeSpan * CancellationToken -> Taskdelay: TimeSpantoken: CancellationTokenpending: TasksucceedNow: 'value -> Deferred<'error,'value> -> boolTries to complete a deferred successfully from a synchronous callback.
ignore: 'T -> unitIgnore the passed value. This is often used to throw away results of a computation. The value to ignore. ignore 55555 // Evaluates to ()
stepped: Flow<unit,Never,int>Axial.Flow`3intAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
child: Fiber<Never,unit>sleep: TimeSpan -> Flow<'env,'error,unit>Suspends the flow for the specified duration, observing cancellation. The duration to sleep. A flow that completes after the specified delay, or is interrupted if cancelled first.
System.TimeSpanRepresents a time interval.
FromSeconds: float -> TimeSpanReturns a that represents a specified number of seconds, where the specification is accurate to the nearest millisecond. A number of seconds, accurate to the nearest millisecond. An object that represents . is less than or greater than . -or- is . -or- is . is equal to .
withClock: IClock -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Overrides the clock within this flow and its descendants.
fork: Flow<'env,'error,'value> -> Flow<'env,'none,Fiber<'error,'value>>Starts a flow in a new fiber without waiting for it to complete. Forking turns a cold flow description into hot child work and returns a handle that can later be joined or interrupted. Prefer zipPar or race when the caller only needs a simple parallel composition. Wait for the handle with Fiber.join or Fiber.awaitExit, and stop it with Fiber.interrupt. The fiber runs in its own scope and releases its scoped resources (anything registered with a scope, such as scopeResource, scopeFinalizer, or a hub subscription) when it settles, whether or not anyone joins it. A value the fiber returns therefore outlives the scoped resources the fiber acquired: a resource returned through Fiber.join has already been released. Use forkResource to acquire a resource in the background and keep it, or zipPar and sequencePar to acquire several in parallel. The flow to fork. A flow that produces a handle.
await: Deferred<'error,'value> -> Flow<'env,'error,'value>Waits for the deferred outcome, preserving success, typed failure, defect, or interruption.
Axial.TestClockadvance: TimeSpan -> Flow<'env,'error,unit>Releases due continuations before returning; never infers idleness from wall time.
waiting: intsleepers: Flow<'env,'error,int>Axial.FiberModuleOperations on a running , the handle returned by Flow.fork. Every operation returns a flow; nothing waits or interrupts until that flow runs. Reading a fiber's outcome through join, await, or interrupt marks it observed, so a defect it died with is not also reported as unobserved.
join: Fiber<'error,'value> -> Flow<'env,'error,'value>Waits for a fiber and returns its value, failing the same way the fiber failed. Joining preserves the child's error channel: a Cause.Fail becomes the same typed error, and interruption and defects remain interruption and defects. Use awaitExit to inspect the outcome instead. The fiber to join. A flow that completes with the fiber's value. let loadProfile : Flow<unit, string, string> = Flow.ok "profile" let loadOrders : Flow<unit, string, int list> = Flow.ok [ 1; 2 ] let page = flow { let! fiber = Flow.fork loadProfile let! orders = loadOrders let! profile = Fiber.join fiber return profile, orders }
Axial.TestPlatformExtensions.FlowrunTestWith: TestPlatform -> 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs with explicitly controlled platform values; it never advances time automatically.
shouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
Requires & types
Requires: open Axial; open System (packages: Axial)val platform: TestPlatformval registered: Deferred<Never,unit>val clock: IClockval notifying: IClockval stepped: Flow<unit,Never,int>TestClock.awaitSleepers n waits, without spinning, until at least n sleeps are registered, so a test can advance
only once the fiber it drives is asleep. TestClock.driveUntilDone fiber advances to each next deadline until the fiber
settles and returns its Exit.
TestClock.advance and sleepers require the installed clock to be a manual clock; using them with a live clock
produces a defect with a diagnostic message. TestClock.advanceAll captures the latest registered deadline when
called and drains only through that horizon. A periodic sleeper cannot extend it; a subsequent sequential sleep
may need another explicit advance. No test runner infers deadlines or advances automatically.
On .NET, due waits are released during AdvanceBy, but a continuation can still hop asynchronously. On Fable,
promise continuations always resume on a later microtask. On both platforms, await the released fiber or its next
signal before making another dependent advance. The TestClock helpers and runTest runners are .NET-only;
Fable tests call ManualClock.AdvanceBy directly and then await the fiber.
A missing advance can be diagnosed through a named fiber's registry dump. Name long-lived workers with
Flow.forkNamed so the dump identifies the sleeper rather than silently waiting.
Clock.fromTimeProvider and toTimeProvider bridge .NET TimeProvider on supported targets. Process live adapters
and Elmish hosts accept explicit clocks because some of their work begins outside a Flow. See
scheduling and retries for the operations that consume runtime time.

