scoop:scoop.http.client:0.1.0
src/lifetime/start.scoop
Selected production source · src/lifetime/start.scoop
1
package scoop.http.client3
// Queued cancellation and entering user work choose exactly one cleanup owner.4
internal fun launchClientTask(5
parent: CoroutineScope,6
beforeStart: (CancellationException) -> Unit,7
block: suspend CoroutineScope.() -> Unit8
): Job {9
val claimed = AtomicBoolean(false)10
val task =11
parent.launch {12
if (claimed.compareAndSet(false, true))13
block(this)14
}15
task.invokeOnCancellation {16
error -> if (claimed.compareAndSet(false, true))17
beforeStart(error)18
}19
return task20
}