# server.Server.with_session

- **Module:** server.Server
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/f0e37052c232636b61d095817046e6bfc8f2ca40/crates/libtmux/src/server.rs#L1464
- **Page:** https://libtmux.org/en/rs/latest/reference/server-server-with_session/

```
server.Server.with_session(self, options: impl Into<NewSessionOptions>, operation: impl AsyncFnOnce(&Session) -> Result<T, E>) -> Result<T, crate::ScopeError<T, E>>
```

Create a session, run an operation with it, then kill it.

[`crate::ScopeError`] retains creation, operation and cleanup failures
separately. If operation and cleanup both fail, both original errors
are returned. Cleanup errors carry [`Error::AfterEffect`] because
creation succeeded.

# Errors

Returns [`crate::ScopeError`] when creation, the operation, or cleanup
fails. The operation's error needs no conversion into [`Error`].

# Cancel safety

Nothing is left behind. Once polled, creation and cleanup run in tasks
of their own, so the session is killed even if this future is dropped
or the operation panics, while the Tokio runtime is alive. A cleanup
failure then has no caller to reach; the `tracing` feature records it.
