Scoop API

scoop:scoop.http.client:0.1.0

src/lifetime/start.scoop

Selected production source · src/lifetime/start.scoop

1package scoop.http.client
3// Queued cancellation and entering user work choose exactly one cleanup owner.
4internal fun launchClientTask(
5 parent: CoroutineScope,
6 beforeStart: (CancellationException) -> Unit,
7 block: suspend CoroutineScope.() -> Unit
8): 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 task