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.JavaScriptWhere work runs
Axial starts work inline. Say where CPU-heavy or blocking work runs with a RunOn — on one flow with Flow.runOn, or on a parallel batch through its Parallelism.
| Workload | Choice |
|---|---|
| Cheap synchronous work | RunOn.Inline or Parallelism.bounded n |
| Naturally waiting I/O | Parallelism.io n |
| CPU-heavy work | RunOn.ThreadPool or Parallelism.cpu |
| Synchronous blocking work | RunOn.DedicatedThread or Parallelism.blocking n |
| Unknown workload | RunOn.adaptive () or Parallelism.adaptive n |
| A required .NET scheduler | RunOn.Scheduler scheduler |
Flow.runOn placement source controls one flow. Flow.traversePar, Flow.traverseParUsing, Flow.forEachPar, and Flow.sequenceParWith apply the placement carried by their Parallelism to each item while preserving the bound.
Wrap CPU-heavy branches individually so they can start concurrently:
> let square value : Flow<string, int> = Flow.delay (fun () -> Flow.ok (value * value)) |> Flow.runOn RunOn.ThreadPool;;
> [ 1; 2; 3 ] |> List.map square |> Flow.sequencePar |> Flow.run ();;val it: Exit<int list,string> = Success [1; 4; 9]square: int -> Flow<string,int>value: intFlowA flow that requires no environment and can fail with a typed error.
stringAn abbreviation for the CLI type . Basic Types
intAn abbreviation for the CLI type . Basic Types
Axial.Flowdelay: (unit -> Flow<'env,'error,'value>) -> Flow<'env,'error,'value>Defers flow construction until execution time. A function that returns the flow to execute. Recursive calls deferred here are consumed by the executor without growing a chain of parent tasks. Work that must run after the recursive call still needs storage until that call finishes. A flow that lazily evaluates the factory when executed. let flow = Flow.delay (fun () -> Flow.succeed 42)
ok: '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 -> ^T2 -> ^T3Overloaded multiplication operator The first parameter. The second parameter. The result of the operation. 8 * 6 // Evaluates to 48
(|>): '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
runOn: RunOn -> Flow<'env,'error,'value> -> Flow<'env,'error,'value>Starts a flow at the requested execution location. This changes only where the wrapped flow starts. It keeps the same environment, cancellation token, runtime, and scope. Cancellation remains cooperative: the wrapped flow observes interruption at its normal check points, such as Flow.ensureNotCanceled. If the token is cancelled before scheduling or while waiting in the scheduler's queue, the flow returns interruption without starting the wrapped flow. On .NET, ThreadPool uses . DedicatedThread gives the synchronous part before the first incomplete await a dedicated thread; later continuations normally resume on the thread pool. Scheduler captures the supplied scheduler across awaits inside the wrapped flow; the caller's continuation resumes on its original scheduler. On JavaScript every location runs inline because JavaScript has one thread. Where the wrapped flow starts. The flow to start there. The wrapped flow, or unchanged for Inline. let parallel = jobs |> List.map (fun job -> compute job |> Flow.runOn RunOn.ThreadPool) |> Flow.sequencePar Fable compatible; JavaScript runs every case inline. Custom schedulers are .NET only.
Axial.RunOnSpecifies where a flow starts running. JavaScript has one thread, so every placement runs inline there.
ThreadPoolStarts work on the .NET thread pool.
Microsoft.FSharp.Collections.ListModuleContains operations for working with values of type . Operations for collections such as lists, arrays, sets, maps and sequences. See also F# Collection Types in the F# Language Guide.
map: ('T -> 'U) -> 'T list -> 'U listBuilds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The function to transform elements from the input list. The input list. The list of transformed elements. let inputs = [ "a"; "bbb"; "cc" ] inputs |> List.map (fun x -> x.Length) Evaluates to [ 1; 3; 2 ] This is an O(n) operation, where n is the length of the list.
sequencePar: Flow<'env,'error,'value> list -> Flow<'env,'error,'value list>Runs all flows concurrently and returns their values in input order. An empty input succeeds immediately. Branches start inline, like async methods passed to Task.WhenAll; use Flow.runOn RunOn.ThreadPool for synchronous CPU-heavy branches. If any flow fails, remaining flows are interrupted through the same structured parallel composition as zipPar. Scoped resources follow zipPar too: when every flow succeeds they move to the caller's scope; when any fails, all of them are released before sequencePar returns.
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
Adaptive placement starts inline and measures only how long invoking a flow holds the calling thread. Time after the flow returns an incomplete task is not counted, so waiting operations remain inline. The default samples three invocation attempts and compares their minimum hold time with a 50 microsecond threshold. Using the minimum prevents one cold/JIT/setup outlier from moving otherwise waiting work to the pool; every sample must exceed the threshold before the learner chooses ThreadPool. Failed and interrupted invocation attempts count as samples because they still held the calling thread. The decision is permanent.
Each RunOn.adaptive () call owns separate memory; Parallelism.adaptive n creates a new learner each time the traversal runs. Use RunOn.adaptiveWith { Threshold = threshold; Samples = samples } to change the default. On JavaScript every placement, including adaptive placement, runs inline.

