# io.github.libtmux.kotlin.Server.liveState

- **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#L38
- **Page:** https://libtmux.org/en/kotlin/latest/reference/io-github-libtmux-kotlin-server-livestate/

```
public suspend fun Server.liveState(
    session: Session,
    scope: CoroutineScope,
    attachTimeout: Duration = config.defaultTimeout().toKotlinDuration(),
): StateFlow<ServerMirror.View>
```

A live, continuously rebuilt view of [server], as a [StateFlow].

Wraps Java's [ServerMirror] rather than reinventing it: every routine case — resnapshot on
notification, on gap, and on reconnect; conflation while a rebuild is in flight; ending once
[session] itself is gone — is already handled once, correctly, inside [ServerMirror]. This
function's only job is pumping [ServerMirror.awaitNewer] on a dedicated thread from
[ExecutionPolicy.streamReads] and publishing what comes back. Named `liveState`, not `ServerMirror`,
so it does not collide with the Java type it wraps.

[scope] owns the returned [StateFlow]'s whole lifetime: closing the mirror is this function's own
`launch`+`finally`, tied to [scope]'s cancellation, so the caller never has to close it by hand.

## Parameters

- `session` (`Session`)
- `scope` (`CoroutineScope`)
- `attachTimeout` (`Duration`): how long to wait for the first attach, and the deadline each later rebuild wait uses to recheck [scope] for cancellation

## Raises

- [`io.github.libtmux.exception.TargetGoneException`](/en/java/latest/reference/io-github-libtmux-exception-targetgoneexception-targetgoneexception/): synchronously if [session]'s server has already gone when this is called; later, the same failure ends [scope] instead, since it surfaces from the launched pump rather than from this call
