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.HttpClient
open Axial.PlatformService
open Axial.Process
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptCreating Flows
Flow.succeed creates a description that succeeds with a value:
let greeting : Flow<string> =
Flow.succeed "Hello"
greeting: Flow<string>FlowA flow that requires no environment and cannot fail with a typed error.
stringAn abbreviation for the CLI type . Basic Types
Axial.Flowsucceed: 'value -> Flow<'env,'error,'value>Alias for ok that reads well in some call sites. The value to wrap in a successful flow. A flow that always succeeds with the provided value. let result = Flow.succeed 42 |> Flow.run () // result = Success 42
type LoadError = UserNotFound
let missing : Flow<LoadError, User> =
Flow.fail UserNotFoundUse Flow.fromTask or Flow.fromAsync when the operation comes from a Task- or Async-returning API and thrown
exceptions are defects:
let readText : Flow<string> =
Flow.fromTask (fun token -> File.ReadAllTextAsync("message.txt", token))
readText: Flow<string>FlowA flow that requires no environment and cannot fail with a typed error.
stringAn abbreviation for the CLI type . Basic Types
Axial.FlowfromTask: (CancellationToken -> Task<'value>) -> Flow<'env,'error,'value>Creates a flow from a cancellable task factory. The factory runs on each execution and receives the runtime's cancellation token, so the flow stays cold and cancellable. Thrown exceptions are recorded as defects (Cause.Die). Use attemptTask when expected exceptions should enter the typed error channel. Starts the operation, observing the supplied cancellation token. .NET only let flow = Flow.fromTask (fun token -> client.GetStringAsync(url, token))
token: CancellationTokenSystem.IO.FileProvides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of objects.
ReadAllTextAsync: string * CancellationToken -> Task<string>Asynchronously opens a text file, reads all the text in the file, and then closes the file. The file to open for reading. The token to monitor for cancellation requests. The default value is . A task that represents the asynchronous read operation, which wraps the string containing all text in the file.
let readText : ExnFlow<string> =
Flow.attemptTask (fun token -> File.ReadAllTextAsync("message.txt", token))The Task and Async interop guide covers cancellation and all supported carriers.
Go Further
- Flow construction reference lists every constructor and conversion.
- Defects explains when an exception should remain a defect and when an attempt constructor is appropriate.

