scoop:scoop.http.client:0.1.0
src/interceptors/resources.scoop
Selected production source · src/interceptors/resources.scoop
1
package scoop.http.client3
internal 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@withLock9
invocation.resources.add(ClientInvocationResource(resource))10
}11
}13
internal 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 -> None21
}22
nonCancellableScope<Unit> {23
for (saved in invocation.resources) {24
if (saved.closed || (clientPresent(retained) && saved.resource === retained!!))25
continue26
saved.closed = true27
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
error38
)39
else40
appendClientCleanup(invocation.cleanupFailure, error)41
Unit42
}43
}44
}45
}46
}