# server.channels.Server.wait_for_channel

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

```
server.channels.Server.wait_for_channel(self, channel: &str, within: Duration) -> Result<ChannelWait, Error>
```

Wait for a `wait-for` channel to be signalled.

The blocking half of [`Server::signal_channel`]. Nothing polls: tmux
releases the wait when the channel is signalled, so a caller costs one
idle client rather than a loop.

This waits for something to *say* it happened. It does not watch a
pane, so what signals the channel is the caller's to arrange -- a
command ending with `tmux wait-for -S <channel>` is the usual shape.

The channel latches. Signalling one nothing is waiting on is kept, and
the next wait returns at once; the latch is one-shot, so a second wait
blocks again. One signal releases every waiter present at the time. So
signalling before the wait starts is safe, which is what makes this
usable for a command that may finish first.

That holds across the supported range. `cmd-wait-for.c` is identical
between 3.5a and 3.7c, and the only changes since 3.2a are an argument
table gaining a field, an accessor replacing a direct index, and a
local being renamed -- none of them near the flag the latch is kept in.
Measured directly on 3.5a and 3.7c.

`within` is capped at [`Server::default_timeout`], because a dispatch
is bounded and this is one: ask for longer by building the server with
a longer timeout.

# Errors

Returns an error when tmux refuses the channel name or cannot be
reached. Running out of time is [`ChannelWait::TimedOut`] rather than
an error, so "nothing signalled it" stays distinct from "the command
did not get through" -- the caller retries only one of those.

## Example

```rust
use libtmux::ChannelWait;
use std::time::Duration;

// Signalling first is safe: the channel keeps it.
server.signal_channel("ready").await?;
let outcome = server.wait_for_channel("ready", Duration::from_secs(5)).await?;
assert_eq!(outcome, ChannelWait::Signalled);

// The latch is spent, so a second wait runs out of time instead.
let again = server.wait_for_channel("ready", Duration::from_millis(200)).await?;
assert_eq!(again, ChannelWait::TimedOut);
```
