flush

open suspend fun flush(timeout: Duration): FlushOutcome

Wait, up to timeout, until a close from this end cannot throw away any send this seam accepted before this call.

The call for "send, then close": without it a frame still queued on this device is lost to the close, and a delay only guesses at how long the queue takes.

Most seams answer FlushOutcome.Unsupported at once today, RoomHubSeam, MeshSeam and NwSeam among them. On those, deleting a working delay just loses the frame sooner, so keep it or an acknowledgement until your fabric answers. What confirms a drain, a list that only grows: LinkSeam over a WebSocket except an OkHttp client, LinkSeam over framed() (so TCP), and InMemoryLoom.

Parameters

timeout

how long to wait. kotlin.time.Duration.INFINITE waits as long as it takes, so it ends only when the barrier is reached, the seam tears, or the caller is cancelled. Zero or less does not wait.

Samples

seam.sendTo(peer, lastFrame)
val outcome = seam.flush(2.seconds)
seam.close()
return when (outcome) {
    FlushOutcome.Drained -> true
    // Not proven, not lost. This fabric cannot tell, the link stalled, or the link ended.
    FlushOutcome.Unsupported, FlushOutcome.TimedOut, is FlushOutcome.Failed -> false
}