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.JavaScriptResources
When a flow opens something that must be closed, pair the two so the close cannot be skipped.
open System.IO
open System.Threading.Tasks
open Axial
let readFirstLine path =
Flow.acquireReleaseWith
(Flow.succeed (File.OpenText path))
(fun reader _ ->
reader.Dispose()
Task.CompletedTask)
(fun reader ->
flow {
return! ColdTask(fun _ -> reader.ReadLineAsync())
})
SystemIOThreadingTasksAxialreadFirstLine: string -> Flow<'a,'b,string>path: stringAxial.FlowacquireReleaseWith: Flow<'env,'error,'resource> -> ('resource -> CancellationToken -> Task) -> ('resource -> Flow<'env,'error,'value>) -> Flow<'env,'error,'value>Acquires a resource, uses it, and always runs the release action. The flow that acquires the resource. The release action to run after the resource is used. The flow that uses the acquired resource. A flow that releases the resource after use, including failure paths. Use this for lexical acquire/use/release. For resources that should live until the surrounding scope closes, use .
succeed: '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
System.IO.FileProvides static methods for the creation, copying, deletion, moving, and opening of a single file, and aids in the creation of objects.
OpenText: string -> StreamReaderOpens an existing UTF-8 encoded text file for reading. The file to be opened for reading. A on the specified path. The caller does not have the required permission. is a zero-length string, contains only white space, or contains one or more invalid characters as defined by . is . The specified path, file name, or both exceed the system-defined maximum length. The specified path is invalid, (for example, it is on an unmapped drive). The file specified in was not found. is in an invalid format.
reader: StreamReaderDispose: unit -> unitReleases all resources used by the object.
System.Threading.Tasks.TaskRepresents an asynchronous operation.
CompletedTask: TaskGets a task that has already completed successfully. The successfully completed task.
flow: FlowBuilderThe universal flow { } computation expression.
ColdTaskReadLineAsync: unit -> Task<string>Reads a line of characters asynchronously from the current stream and returns the data as a string. A task that represents the asynchronous read operation. The value of the parameter contains the next line from the stream, or is if all the characters have been read. The number of characters in the next line is larger than . The stream has been disposed. The reader is currently in use by a previous read operation.
That covers the common case: the resource's lifetime is one expression, and use / use! inside flow { } covers
it too when the lifetime matches a lexical block.
A resource sometimes has to outlive the expression that acquired it — acquired in one subflow, used by several others, released only when the whole execution finishes. That is a scope, and it is covered in scopes and resources.

