# tmux_scope

- **Package:** libtmux_erlang
- **Language:** Erlang
- **Kind:** module
- **Source:** https://github.com/libtmux/libtmux-erlang/blob/d1b6308440cf9eb8f6647e7ae434bce60e849368/apps/libtmux_erlang/src/tmux_scope.erl#L1
- **Page:** https://libtmux.org/en/erlang/latest/reference/tmux_scope/

Run synchronous work and cleanup while preserving both outcomes.

Use `run/2` around a resource whose handle remains in the caller's scope.
Use `run_or_error/2` for nested scopes or fail-fast programs that need the
callback's value directly and raise when cleanup fails.
`tmux_server:with_server/2` and `tmux_server:with_owned/2` also acquire their
resources and add recovery handles when cleanup fails. This module owns no
process, timeout or retry policy; the supplied functions own those contracts.

## Members

### Common operations

- [`run_or_error/2`](/en/erlang/latest/reference/tmux_scope-run_or_error-2/) (function): Run work and cleanup with `run/2`, returning the callback value directly. Raises {scope_cleanup_failed, Failure} if cleanup fails, retaining both outcomes in `t:failure/0`. With successful cleanup, callback exceptions retain their original reason and stack. Nested raising scopes propagate an inner failure through the outer scope while still attempting outer cleanup.
- [`run/2`](/en/erlang/latest/reference/tmux_scope-run-2/) (function): Run a callback, then attempt cleanup once, synchronously in the calling process. This function performs only the I/O supplied by those functions. The callback has no library duration timer. Abrupt uncatchable caller death remains subject to each resource's existing ownership policy.

### Other members

- [`exception/0`](/en/erlang/latest/reference/t-tmux_scope-exception-0/) (typealias): The original exception class, reason and stack, retained as evidence.
- [`failure/0`](/en/erlang/latest/reference/t-tmux_scope-failure-0/) (typealias): Both outcomes when cleanup failed. primary contains the callback's ordinary return or exception; cleanup contains its separate error or exception. Resource-specific wrappers may add recovery handles to this map.

## Guides

Pages that discuss `tmux_scope`.

- [Native API documentation](/en/erlang/latest/guides/api-documentation/)
