Scoop API

scoop:scoop.http.server:0.1.0

src/deadline.scoop

Selected production source · src/deadline.scoop

1package scoop.http.server
3import scoop.time.Duration
5/** A server-owned deadline that expired after its operation's cleanup completed. */
6public class HttpServerTimeoutException internal constructor(
7 /** The operation whose deadline expired. */
8 public val operation: String,
9 /** The configured duration. */
10 public val limit: Duration
11): Exception(Some("HTTP server deadline expired: " + operation))
13internal suspend fun <T> serverDeadline(
14 duration: Duration?,
15 operation: String,
16 block: suspend () -> T
17): T {
18 if (!present(duration))
19 return block()
20 val deadline = RequestDeadline(duration, operation)
21 try {
22 return coroutineScope<T> {
23 deadline.start(job)
24 block()
25 }
26 } catch (error: CancellationException) {
27 throw deadline.selectedFailure ?: error
28 } finally {
29 deadline.stop()
30 }