Scoop API

scoop:scoop.http.asyncio:0.1.0

src/websocket/waits.scoop

Selected production source · src/websocket/waits.scoop

1package scoop.http.asyncio
3internal fun <T> succeedWsWait(wait: WsWait<T>, value: T, actions: ArrayList<() -> Unit>) {
4 val continuation = wait.continuation
5 wait.continuation = None
6 when (continuation) { case Some(val next) -> actions.add { next.resume(value) }; case None -> {} }
7}
9internal fun <T> failWsWait(wait: WsWait<T>, error: Throwable, actions: ArrayList<() -> Unit>) {
10 val continuation = wait.continuation
11 wait.continuation = None
12 when (continuation) { case Some(val next) -> actions.add { next.resumeWithException(error) }; case None -> {} }
15internal fun listenWsLife(state: WsState, life: WsLife, job: Job) {
16 val listener = job.invokeOnCancellation { error ->
17 state.lock.withLock { if (!life.complete && !life.closed) abortWs(state, Some(error)); Unit }
18 driveWs(state)
19 }
20 val finished = state.lock.withLock {
21 if (state.closing || life.complete || life.closed) true else { life.listener = Some(listener); false }
22 }
23 if (finished) listener.dispose()
26internal fun detachWsLife(life: WsLife, actions: ArrayList<() -> Unit>) {
27 val listener = life.listener
28 life.listener = None
29 when (listener) { case Some(val value) -> actions.add { value.dispose() }; case None -> {} }
32internal fun completeWsLife(life: WsLife, actions: ArrayList<() -> Unit>) {
33 life.complete = true
34 detachWsLife(life, actions)