FIO is an IO monad plus lightweight fibers (green threads) for building concurrent and asynchronous F# applications. Effects are described as pure, lazy values and run by a pluggable runtime β so your program is a composable description that stays referentially transparent until you hand it to a runtime. The API takes its cues from ZIO.
- Typed effects β
FIO<'A, 'E>tracks both the success value and the error in the type - Fibers & channels β green threads via
.Fork()/.Join()and typed message passing - Structured concurrency β fail-fast parallel combinators that interrupt losers automatically
- Finalizer guarantees β
Ensuringfinalizers run on success, error, and interruption - Composable β the
fio { }computation expression plus a rich set of operators
dotnet add package FSharp.FIOopen FIO.DSL
open FIO.App
open FIO.Console
type App() =
inherit FIOApp<unit, exn>()
override _.effect = fio {
do! Console.printLine "What is your name?" id
let! name = Console.readLine id
do! Console.printLine $"Hello, {name}!" id
}
[<EntryPoint>]
let main _ = App().Run()Fork effects onto fibers, run them in parallel, and compose the results β losers are interrupted automatically on the first failure.
open FIO.DSL
// Run two effects in parallel with <&> and collect both results as a tuple.
let taskA = FIO.succeed "Task A completed! β
"
let taskB = FIO.succeed (200, "Task B OK β
")
let both = taskA <&> taskB
// Or fork/join explicitly.
let forked = FIO.succeed("Hello, concurrency! π").Fork() >>= fun fiber -> fiber.Join()More in examples/ β the DSL, App, HTTP, Sockets, and WebSockets tours.
- Effects β lazy, composable
FIO<'A, 'E>with typed errors - Fibers β green threads for scalable concurrency
- Channels β typed message passing between fibers
- Structured concurrency β fail-fast
ZipPar,Race, andforEachParthat interrupt losers automatically - Composition β
fio { }CE, operators (>>=,<&>,<|>), combinators - Modules β
Console
Effects are interpreted by a runtime. Pick one explicitly, or use DefaultRuntime.
| Runtime | Notes |
|---|---|
DirectRuntime |
Single-threaded, synchronous. Handy for tests and simple programs. |
PollingRuntime |
Multi-threaded, linear-time handling of blocked fibers (polling). |
SignalingRuntime |
Multi-threaded, event-driven handling of blocked fibers. |
WorkStealingRuntime |
Multi-threaded, work-stealing scheduler. The default. |
DefaultRuntime = WorkStealingRuntime β FIOApp uses it unless you override _.runtime.
| Package | Description |
|---|---|
FSharp.FIO |
Core β effects, fibers, channels, runtimes |
FSharp.FIO.Http |
HTTP server (Kestrel) |
FSharp.FIO.Sockets |
TCP sockets |
FSharp.FIO.WebSockets |
WebSockets |
Each extension library has its own README with API details: Http Β· Sockets Β· WebSockets.
Issues and pull requests welcome. See CONTRIBUTING.md, the Code of Conduct, and the Security Policy.