scoop:scoop.http.client:0.1.0
src/sse/timer.scoop
Selected production source · src/sse/timer.scoop
1
package scoop.http.client3
import scoop.platform.time.MonotonicTimeSource4
import scoop.time.Duration6
internal fun startClientSseTimer(state: ClientSseState) {7
val limit = state.sequence.timeouts.total ?: return8
val scope = state.client.lock.withLock { state.client.scope!! }9
val timer = scope.launch suspend {10
try {11
val remaining = limit - (MonotonicTimeSource.markNow() - state.sequence.started!!)12
if (remaining > Duration.ZERO) state.client.loop.sleep(remaining)13
stopClientSse(state, state.timeout())14
} catch (error: Throwable) {15
if (!(error is CancellationException)) stopClientSse(state, error)16
}17
}18
state.client.lock.withLock { state.timer = Some(timer) }19
}