Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

Swift API

Swift documentation

Server.connected(attachingTo:_:)

Swift
  • Python Unavailable
  • Ruby Unavailable
  • Lua Unavailable
  • TypeScript Unavailable
  • Rust Unavailable
  • Go Unavailable
  • Java Unavailable
  • .NET Unavailable
  • C++ Unavailable
  • Swift

View as Markdown

Declared in
Server
Package
libtmux-swift
Source
Sources/LibTmux/ControlMode.swift
connected(attachingTo:_:) ( attachingTo : String , body : @escaping (Server, ControlSession) async throws -> Result ) → Result
methodasync [source]
methodasync [source]
connected(attachingTo:_:)

Runs body with every command carried by one live connection instead of a new tmux process each time.

The server handed to body is this server: the same calls, the same return types, the same errors. Only how the work reaches tmux changes.

A connection is a client, and tmux has no client that is attached to nothing — a control client with no target runs tmux's default command and creates a session. So the connection attaches to session, and that is visible in what the server reports about itself: that session reads as attached, and Server/clients() includes the connection. Nothing else differs.

The connection is handed over too, because it can do one thing a process cannot: report what changed without being asked. That capability exists only here, and so does the value carrying it — there is no way to write a %output reader against a server that has no connection.

The handed-out values do not keep the connection alive. Do not return or store them; calls made after body ends fail because the process has already been reaped.

  • Parameters:
    • session: the session to attach to, which must already exist.
    • body: the work to run, given this server and the connection carrying it.
  • Throws: TmuxError/connectionClosed if the connection ends before body, including when body detaches its own client.

Examples

let names = try await server.connected(attachingTo: "main") { server, _ in
try await server.sessions().map(\.name)
}
Raises

0 declared, 0 inherited

Esc

Type to search.