Scoop API

scoop:scoop.http.client:0.1.0

src/interceptors/resources.scoop

Selected production source · src/interceptors/resources.scoop

1package scoop.http.client
3internal fun rememberClientInvocationResult(invocation: ClientInvocation, result: HttpCallResult) {
4 val resource = clientResultResource(result)
5 invocation.client.lock.withLock {
6 for (saved in invocation.resources)
7 if (saved.resource === resource)
8 return@withLock
9 invocation.resources.add(ClientInvocationResource(resource))
10 }
13internal suspend fun closeClientInvocationResults(
14 invocation: ClientInvocation,
15 keep: HttpCallResult?
16) {
17 val retained =
18 when (keep) {
19 case Some(val value) -> Some(clientResultResource(value));
20 case None -> None
21 }
22 nonCancellableScope<Unit> {
23 for (saved in invocation.resources) {
24 if (saved.closed || (clientPresent(retained) && saved.resource === retained!!))
25 continue
26 saved.closed = true
27 try {
28 saved.resource.close()
29 }
30 catch (error: Throwable) {
31 invocation.client.lock.withLock {
32 invocation.cleanupFailure =
33 if (clientPresent(invocation.failure))
34 collectClientSecondary(
35 invocation.failure!!,
36 invocation.cleanupFailure,
37 error
38 )
39 else
40 appendClientCleanup(invocation.cleanupFailure, error)
41 Unit
42 }
43 }
44 }
45 }