# types.ConnectedServer.waitFor

- **Module:** types
- **Package:** libtmux
- **Language:** TypeScript
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-ts/blob/073b9d7dedad900bff6f5ec0ea47794e40225870/packages/libtmux/src/types.ts#L1275
- **Page:** https://libtmux.org/en/ts/latest/reference/types-connectedserver-waitfor/

```
waitFor(
  matches: (snapshot: ServerSnapshot) => boolean,
  options?: WaitForOptions,
): Promise<ServerSnapshot>
```

Resolve once the server satisfies `matches`, or reject on timeout.

This is the join between a snapshot and the stream: it subscribes first,
then reads, so a change landing between those two steps is still seen.
Doing it the other way round — read, then subscribe — waits forever on a
condition that already came true. Notifications trigger immediate reads;
bounded polling covers state changes tmux does not announce. An unannounced
transition must persist until a sample to be observable.

## Examples

```ts
await live.waitFor((server) => server.windows.exists({ name: "build" }));
```

## Parameters

- `matches` (`(snapshot: ServerSnapshot) => boolean`)
- `options?` (`WaitForOptions`)

## Raises

- [`WaitTimeoutError`](/en/ts/latest/reference/errors-waittimeouterror/): when the deadline passes with the condition unmet.
- [`LibTmuxError`](/en/ts/latest/reference/errors-libtmuxerror/): when the connection ends first, which says nothing about the condition and so is not the same answer.

## Guides

Pages that discuss `waitFor`.

- [Waiting and retrying](/en/ts/latest/topics/waiting-and-retry/)
