Core Library0.xAPI Reference

Choose documentation 3

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.

Swift API

method libtmux-swift latest

Server.connected(attachingTo:_:)

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

Source and package
Qualified name
Server.connected(attachingTo:_:)
Declared in
Server
Package
libtmux-swift
Source
Sources/LibTmux/ControlMode.swift
connected( attachingTo: String, body: @escaping (Server, ControlSession) async throws -> Result ) -> Result

Description#

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)
}
Type parameters
Parameters
Raises

Guides#

Pages that discuss connected(attachingTo:_:).

Esc

Type to search.

Reference previewOpen reference