# server.Server.chain

- **Module:** server.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/server.rs#L556
- **Page:** https://libtmux.org/reference/rs/server-server-chain/

```
server.Server.chain(self, chain: CommandChain) -> Result<CommandResult, Error>
```

Dispatch several commands as one `tmux a \; b` invocation.

One process, one exit status, one merged stdout. tmux runs the chain up
to the first failure and drops the remainder, so this trades the ability
to tell *which* command failed for a single round trip. The merged
result is identical whichever member failed: use it when the commands
succeed or fail as a unit, and [`Server::cmd`] when you need to know
where a failure happened.

# Errors

Returns an error when the process cannot be started, captured, awaited,
or is cancelled by timeout or shutdown. A command tmux refuses is
reported through the returned [`CommandResult`], not as an error.

## Example

```rust
use libtmux::{Command, CommandChain};

let server = libtmux::Server::builder()
    .socket_path("/tmp/libtmux-rs-test/chain-example-absent.sock")
    .build()?;
let chain = CommandChain::new(Command::new("list-sessions"))
    .then(Command::new("list-panes"));
let result = server.chain(chain).await?;
assert!(result.exit_code().is_some());
server.shutdown().await?;
```
