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.using(_:_:)

Runs body with this server in mode.

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

Description#

The one switch. Every call inside is the call you would write anyway and hands back the type it would hand back anyway; mode decides only how it travels. Reach for this when the choice is made at runtime — a flag, a config, a benchmark running both — so it stays a value rather than two shapes of code:

Scoped even for TmuxMode.direct, where nothing needs closing, so that the two read identically at the call site. connected(attachingTo:_:) is the same thing with the connection handed over as well, for the one capability a process does not have.

Modes nest, and the innermost wins: using(.direct) inside a connected scope gives back a server that spawns processes, which is the supported way to keep one call off a connection. A server handed to a connected body does not keep that connection alive when returned or stored.

Examples#

let mode: TmuxMode = attachToExisting ? .connected(to: "main") : .direct
let names = try await server.using(mode) { server in
try await server.sessions().map(\.name)
}
Type parameters
Parameters
Raises
Esc

Type to search.

Reference previewOpen reference