Mirror.startRefreshing
Mirrors a server, also capturing whenever it has been quiet for an interval.
Source and package
- Qualified name
-
LibTmux .FSharp .Mirror. start Refreshing - 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. startRefreshing: cancellationToken : CancellationToken -> every: TimeSpan -> anchor: LibTmux -> Task<Server.Session Mirror > -
- Parameters
-
-
every(TimeSpan)
- Errors
-
-
System
.Argument – The interval is negative.Out Of Range Exception
-
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 ofLibTmux.FSharpon NuGet: View sourceExample.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 withLibTmux.Server.CreateOwnedAsync;use!disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View sourceProgram.fsComplete program // fsharp-snippet: LiveStateopen Systemopen System.IOopen System.Threadingopen LibTmuxopen LibTmux.FSharplet runAsync () =task {use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 20.)let token = deadline.Tokenlet socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"use _cleanup ={ new IDisposable withmember _.Dispose() = socketRoot.Delete true}let options =ServerConnectionOptions(SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null")use! owned = options |> Server.createOwned tokenlet! 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 tokendo! 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-snippetBuild 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.dllExpected program output from each framework:
windows: shell, logssleeping panes: 1newer view: true
Same owner
containment 1 of 6 shownOther members of LibTmux.FSharp.Mirror whose names share startRefreshing. They sit on the same type; that does not make them behave alike.
Recorded calls
source callsThe 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 materialThe tmux commands behind startRefreshing.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Guides
task materialPages that discuss startRefreshing.
- Guides
- Topics