# tmux_command:wait_for/2

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_command.erl#L188
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_command-wait_for-2/

```
wait_for(Channel, Action)
-spec wait_for(binary(), wait_action()) ->
                  {ok, t()} | {error, map()}.
```

Build a native [`wait-for`](/en/tmux/latest/manual/wait-for/) command without I/O. Channels are nonempty NUL-free binary names, subject to the command reservation in `raw/2`; neither shell nor format expansion occurs. Submit through `tmux_operation:start/3` for a wait that leaves the caller free, or through `tmux_server:command/3` to await it.

`signal` wakes current waiters. On an unlocked channel with no waiters or
pending wakeup, it retains one wakeup for a later wait. Signaling that channel
again before a wait can clear the pending state. Signals are neither counted
nor reliably coalesced events; send once per expected wait. Channel names are
shared by all clients of the server. Use separate names for signaling and
locking. `lock` acquires an advisory channel lock or waits
for an explicit `unlock`; a completed command client's exit does not release
its acquired lock. Unlocking an unlocked channel is a native command error.

Cancellation retires the library client. It does not undo a signal or release
a lock that may already have been acquired; an uncertain lock outcome needs
application coordination before another unlock. This is not an owned mutex.

## Examples

```erlang
1> {ok, Signal} = tmux_command:wait_for(<<"build-ready">>, signal), ok.
ok
2> tmux_command:argv(Signal).
[<<"wait-for">>,<<"-S">>,<<"--">>,<<"build-ready">>]
```

## Parameters

- `Channel` (`binary()`)
- `Action` (`wait_action()`)

## Guides

Pages that discuss `wait_for/2`.

- [Native API documentation](/en/erlang/latest/guides/api-documentation/)
- [Apply configuration and await its completion signal](/en/erlang/latest/guides/configuration/)

## In other ports

Wait for, signal or lock a channel

| Language | Equivalent |
| --- | --- |
| Python | [`libtmux.Server.wait_for`](/en/py/latest/reference/libtmux-server-wait_for/) (method) |
| Ruby | [`LibTmux::Server#wait_for`](/en/ruby/latest/reference/libtmux-server-wait_for/) (method) |
| Haskell | No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing. |
| TypeScript | no equivalent on `Server` |
| Rust | [`server.Server.wait_for_channel`](/en/rs/latest/reference/server-server-wait_for_channel/) (method) |
| Go | [`tmux.Server.WaitFor`](/en/go/latest/reference/tmux-server-waitfor/) (method) |
| Java | no equivalent on `Server` |
| C# | [`LibTmux.Server.WaitForAsync`](/en/csharp/latest/reference/libtmux-server-waitforasync/) (method) |
| C++ | [`libtmux::Server::wait_for`](/en/cxx/latest/reference/libtmux-server-wait_for/) (method) |
| Swift | [`Server.wait(for:)`](/en/swift/latest/reference/server-wait(for-)/) (method) |
| OCaml | [`Libtmux_unix.Client.wait_for`](/en/ocaml/latest/reference/libtmux_unix-client-wait_for/) (function) |
| Perl | No dedicated equivalent in the selected Perl surface. Explicit Server::cmd remains available for native tmux commands. |

No equivalent is recorded in Lua, PowerShell, Julia, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.
