scoop:scoop.http.asyncio:0.1.0
src/websocket/waits.scoop
Selected production source · src/websocket/waits.scoop
1
package scoop.http.asyncio3
internal fun <T> succeedWsWait(wait: WsWait<T>, value: T, actions: ArrayList<() -> Unit>) {4
val continuation = wait.continuation5
wait.continuation = None6
when (continuation) { case Some(val next) -> actions.add { next.resume(value) }; case None -> {} }7
}9
internal fun <T> failWsWait(wait: WsWait<T>, error: Throwable, actions: ArrayList<() -> Unit>) {10
val continuation = wait.continuation11
wait.continuation = None12
when (continuation) { case Some(val next) -> actions.add { next.resumeWithException(error) }; case None -> {} }13
}15
internal 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()24
}26
internal fun detachWsLife(life: WsLife, actions: ArrayList<() -> Unit>) {27
val listener = life.listener28
life.listener = None29
when (listener) { case Some(val value) -> actions.add { value.dispose() }; case None -> {} }30
}32
internal fun completeWsLife(life: WsLife, actions: ArrayList<() -> Unit>) {33
life.complete = true34
detachWsLife(life, actions)35
}