Scoop API

scoop:scoop.http.client:0.1.0

src/sse/timer.scoop

Selected production source · src/sse/timer.scoop

1package scoop.http.client
3import scoop.platform.time.MonotonicTimeSource
4import scoop.time.Duration
6internal fun startClientSseTimer(state: ClientSseState) {
7 val limit = state.sequence.timeouts.total ?: return
8 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) }