Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Layers
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.PlatformService
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptYour First Application
Use App.run when a Flow is the root of an application. It carries cancellation from the calling Async and returns
after the root scope and its resources have closed.
Show page setup
// Setup for the checked example on this page.
open Axial
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualopen Axial
let application : Flow<string> =
flow {
return "Hello from Flow"
}
let run () =
async {
let! exit = App.run () application
match exit with
| Exit.Success message -> printfn "%s" message
| Exit.Failure cause -> printfn "%s" (Cause.prettyPrint string cause)
}
Axialapplication: Flow<string>FlowA flow that requires no environment and cannot fail with a typed error.
stringAn abbreviation for the CLI type . Basic Types
flow: FlowBuilderThe universal flow { } computation expression.
run: unit -> Async<unit>async: AsyncBuilderBuilds an asynchronous workflow using computation expression syntax. let sleepExample() = async { printfn "sleeping" do! Async.Sleep 10 printfn "waking up" return 6 } sleepExample() |> Async.RunSynchronously
exit: Exit<string,Never>Axial.AppStarts and controls root Flow applications without requiring an external hosting framework.
run: 'env -> Flow<'env,'error,'value> -> Async<Exit<'value,'error>>Runs a root workflow to completion using the caller's asynchronous cancellation token. The explicit environment supplied to the root workflow. The root workflow to run. The final exit after the root scope has closed. Fable compatible
Axial.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.
message: stringprintfn: Printf.TextWriterFormat<'T> -> 'TPrint to stdout using the given format, and add a newline. The formatter. The formatted result. See Printf.printfn (link: ) for examples.
FailureThe workflow failed due to a specific cause.
cause: Cause<Never>Axial.CauseprettyPrint: ('error -> string) -> Cause<'error> -> stringPretty prints a cause tree for diagnostics.
string: 'T -> stringConverts the argument to a string using ToString. For standard integer and floating point values and any type that implements IFormattable, ToString conversion uses CultureInfo.InvariantCulture. The input value. The converted string. string 'A' // evaluates to "A" string 0xff // evaluates to "255" string -10 // evaluates to "-10"
Requires & types
Requires: open Axial (packages: Axial)val application: Flow<string>val run: unit -> Async<unit>App.run () application |> Async.RunSynchronously |> shouldEqual (Exit.Success "Hello from Flow" : Exit<string, Never>)
Axial.AppStarts and controls root Flow applications without requiring an external hosting framework.
run: 'env -> Flow<'env,'error,'value> -> Async<Exit<'value,'error>>Runs a root workflow to completion using the caller's asynchronous cancellation token. The explicit environment supplied to the root workflow. The root workflow to run. The final exit after the root scope has closed. Fable compatible
application: Flow<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
Microsoft.FSharp.Control.FSharpAsyncHolds static members for creating and manipulating asynchronous computations. See also F# Language Guide - Async Workflows. Async Programming
RunSynchronously: Async<'T> * int option * CancellationToken option -> 'TRuns the asynchronous computation and await its result. If an exception occurs in the asynchronous computation then an exception is re-raised by this function. If no cancellation token is provided then the default cancellation token is used. The computation is started on the current thread if is null, has of true, and no timeout is specified. Otherwise the computation is started by queueing a new work item in the thread pool, and the current thread is blocked awaiting the completion of the computation. The timeout parameter is given in milliseconds. A value of -1 is equivalent to . The computation to run. The amount of time in milliseconds to wait for the result of the computation before raising a . If no value is provided for timeout then a default of -1 is used to correspond to . The cancellation token to be associated with the computation. If one is not supplied, the default cancellation token is used. The result of the computation. Starting Async Computations printfn "A" let result = async { printfn "B" do! Async.Sleep(1000) printfn "C" 17 } |> Async.RunSynchronously printfn "D" Prints "A", "B" immediately, then "C", "D" in 1 second. result is set to 17.
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.
stringAn abbreviation for the CLI type . Basic Types
Axial.NeverRepresents an error channel that cannot occur.
Requires & types
Requires: open Axial (packages: Axial)run is the entry point: call run () |> Async.RunSynchronously from a [<EntryPoint>], or hand the same Async
to an ASP.NET Core or Node host. The () value is the environment because this workflow has no dependencies. An
application with an AppEnv record passes its live value in the same position.
Use App.start when a signal handler, desktop window, UI component, or external host will request shutdown later.
The Application Lifecycle guide covers start and stop ownership. Hosting guides show the .NET, Node, and browser boundaries.
Related guides
- Application Lifecycle covers
App.start, coordinated stop, and lifecycle ownership. - Scopes and Resources explains finalizers and acquisition/release safety.
- Hosting connects the root application to .NET, Node, or browser hosts.

