# io.github.libtmux.kotlin.Server.withLiveState

- **Module:** io.github.libtmux.kotlin
- **Package:** io.github.libtmux:libtmux-kotlin
- **Language:** Kotlin
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-java/blob/f56392b5d9bc7f1f9c1631842333fb90f3d82d40/libtmux-kotlin/src/main/kotlin/io/github/libtmux/kotlin/LiveState.kt#L86
- **Page:** https://libtmux.org/en/kotlin/latest/reference/io-github-libtmux-kotlin-server-withlivestate/

```
public suspend fun <R> Server.withLiveState(
    session: Session,
    attachTimeout: Duration = config.defaultTimeout().toKotlinDuration(),
    block: suspend (StateFlow<ServerMirror.View>) -> R,
): R
```

As [liveState], scoped to [block]: opens the live view, runs [block] against it, and cancels the background pump before returning — the same `withServer`/`withControl` shape, for the one resource [liveState] itself cannot close on its own.

[liveState]'s pump runs until [scope] ends, by design (a caller collecting it for the life of a
program passes its own long-lived scope) — which means a bare `coroutineScope { liveState(...) }`
never returns: `coroutineScope` waits for every child, the pump included, and nothing inside it
asks the pump to stop. This cancels that one child explicitly once [block] is done, whether it
returns or throws.

## Parameters

- `session` (`Session`)
- `attachTimeout` (`Duration`)
- `block` (`suspend`)
