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.JavaScript

Creating Flows

Flow.succeed creates a description that succeeds with a value:

let greeting : Flow<string> =
    Flow.succeed "Hello"
`Flow.fail` creates an expected typed failure:
type LoadError = UserNotFound

let missing : Flow<LoadError, User> =
    Flow.fail UserNotFound
Neither value runs when it is created.

Use 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))
Use an `attempt` constructor when thrown exceptions are expected interop failures that callers should handle:
let readText : ExnFlow<string> =
    Flow.attemptTask (fun token -> File.ReadAllTextAsync("message.txt", token))
The distinction is deliberate. `fromTask` preserves an unexpected exception as a defect; `attemptTask` places it in the typed error channel.

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.