# pane.Pane.wait_until

- **Module:** pane.Pane
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/pane/observe.rs#L438
- **Page:** https://libtmux.org/en/rs/latest/reference/pane-pane-wait_until/

```
pane.Pane.wait_until(self, within: Duration, settled: impl FnMut(&[TmuxText]) -> bool) -> Result<PaneWait, Error>
```

Wait until `settled` holds for this pane's captured lines.

For what a literal [`Pane::wait_for_text`] cannot say: a line equal to
something rather than containing it, a count, a pattern, the shape of
the last line. `settled` sees what [`Pane::capture_with`] returns for
`CaptureOptions::history().join_wrapped()`: scrollback and screen, one
entry per line, a line tmux wrapped joined back into one, and the
screen's unused rows as empty lines at the end.

Looks are the ones [`Pane::wait_for_text`] describes: 120ms apart,
the first before any sleep, so lines already there answer at once. A
pane whose process ends answers [`PaneWait::Dead`] rather than running
to the deadline. It polls even on a handle routed through
`Server::over_control_mode`, because that connection's `%output`
belongs to whoever reads its events, so waking on it would attach a
second client per wait to save under three milliseconds on a marker
(`benches/waits.rs`).

A `query::Matcher` over one line fits as
`|lines| lines.iter().any(|line| matcher.matches(line))`.

# Errors

Returns an error when tmux cannot be reached or refuses a look, which
includes a pane that has been closed. Running out of time is
[`PaneWait::TimedOut`], not an error.

# Cancel safety

Nothing happened. A look only reads, so a future dropped mid-look
leaves tmux as it was, and output produced in the meantime stays in the
scrollback, up to `history-limit`, for the next wait to find.

## Example

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

pane.send_line("for n in 1 2 3; do echo tick; done").await?;

// The echoed command contains `tick`; only the output is a line equal to it.
let ticked = pane
    .wait_until(Duration::from_secs(10), |lines| {
        lines.iter().filter(|line| **line == "tick").count() == 3
    })
    .await?;
assert_eq!(ticked, PaneWait::Arrived);
```
