Core Library0.xAPI reference

Choose documentation 1

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

MoreLess about this notice

function libtmux-fsharp

Mirror.startRefreshing

Mirrors a server, also capturing whenever it has been quiet for an interval.

Source and package
Qualified name
LibTmux.FSharp.Mirror.startRefreshing
Namespace
LibTmux.FSharp
Declared in
Mirror
Package
LibTmux.FSharp
Source
src/LibTmux.FSharp/Control.fsi
F# value signaturesDeclares the name and type of a value or function in a signature.Language documentation startRefreshing: cancellationToken: CancellationToken -> every: TimeSpan -> anchor: LibTmux.Session -> Task<ServerMirror>

Description

The caller owns and asynchronously disposes the returned mirror.

Parameters
Errors

Examples

Keep a current copy of a server's sessions, windows and panes as tmux announces changes, and wait until it shows a state instead of polling. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as Example.fsproj. It references the 0.1.1 release of LibTmux.FSharp on NuGet: View source

Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.fs. It creates a private server with LibTmux.Server.CreateOwnedAsync; use! disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View source

Program.fsComplete program
// fsharp-snippet: LiveState
open System
open System.IO
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 20.)
let token = deadline.Token
let socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"
use _cleanup =
{ new IDisposable with
member _.Dispose() = socketRoot.Delete true
}
let options =
ServerConnectionOptions(
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null"
)
use! owned = options |> Server.createOwned token
let! session =
owned.Value.CreateSessionAsync(
NewSessionRequest(Name = "work", WindowName = "shell", Command = "/bin/sh"),
token
)
// Captures again on each change tmux announces, and every 200 ms for
// changes it does not, such as the command a pane runs.
use! mirror =
session |> Mirror.startRefreshing token (TimeSpan.FromMilliseconds 200.)
let! _ =
session.CreateWindowAsync(NewWindowRequest(Name = "logs", Command = "/bin/sh"), token)
let! withLogs =
mirror
|> Mirror.waitUntil token (TimeSpan.FromSeconds 5.) (fun view ->
view.Server.Windows |> Seq.exists (fun window -> window.Name = "logs"))
let! panes = session |> Session.panes |> Query.list token
do! panes[0] |> Pane.sendLine token "exec sleep 30"
// tryWaitUntil answers None when no view matched in time.
let! sleeping =
mirror
|> Mirror.tryWaitUntil token (TimeSpan.FromSeconds 5.) (fun view ->
view.Server.Panes |> Seq.exists (fun pane -> pane.CurrentCommand = "sleep"))
printfn "windows: %s" (String.Join(", ", [ for window in withLogs.Server.Windows -> window.Name ]))
match sleeping with
| Some sleeping ->
printfn
"sleeping panes: %d"
(sleeping.Server.Panes
|> Seq.filter (fun pane -> pane.CurrentCommand = "sleep")
|> Seq.length)
printfn "newer view: %b" (sleeping.Epoch > withLogs.Epoch)
| None -> printfn "no pane ran sleep within five seconds"
}
runAsync().GetAwaiter().GetResult()
// endfsharp-snippet

Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:

Terminal window
$ dotnet build Example.fsproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

windows: shell, logs
sleeping panes: 1
newer view: true

Same owner

containment 1 of 6 shown

Other members of LibTmux.FSharp.Mirror whose names share startRefreshing. They sit on the same type; that does not make them behave alike.

All 6 members of Mirror

Recorded calls

source calls
No call edges in the F# model.

The F# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.FSharp.Mirror.startRefreshing.

tmux command

task material

The tmux commands behind startRefreshing.

tmux C API

task material

The C declarations in tmux that implement these commands.

Guides

task material

Pages that discuss startRefreshing.

Esc
Search in

Type to search.

Reference previewOpen reference