# LibTmux.Server.with_owned/2

- **Module:** LibTmux
- **Package:** libtmux
- **Language:** Elixir
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-elixir/blob/5bacf40788b43a5af27bb3656e727a921ba2db40/lib/libtmux/server.ex#L397
- **Page:** https://libtmux.org/en/elixir/pr-173/reference/libtmux-server-with_owned-2/

```
with_owned(options, fun)
@spec with_owned([start_option()], (t() -> result)) ::
        result
      when result: term()
```

Starts a private server, calls `fun` with it and stops it afterwards.

Takes the options of `start/1`. Returns the value of `fun`. A start failure
raises its `LibTmux.Error` before `fun` runs. The server stops when `fun`
returns, raises, throws or exits. If `fun` completes and the stop fails,
`with_owned/2` raises the stop error; a failing stop never replaces an
exception from `fun`.

## Type parameters

- `result` (bound `term()`)

## Parameters

- `options` (`[start_option()]`)
- `fun` (`(t() -> result)`)

## Examples

```elixir
alias LibTmux.Server

Server.with_owned([executable: System.find_executable("tmux")], fn server ->
  command = {:argv, ["/bin/cat"]}
  {:ok, _} = Server.new_session(server, "demo", command: command)
  Server.snapshot!(server)
end)
```

## Guides

Pages that discuss `with_owned/2`.

- [Capture a pane and read it](/en/elixir/pr-173/examples/capture-and-read/)
