ContinuousSessionReceiver

一组 Session 的元素之一, 用来在异步中接收 ContinuousSessionProvider 推送的事件 T 并根据此事件为其返回结果 R

val session = context.session(Key()) {
val next = await { v -> v.toResult() } // 假设 toResult() 将事件转化为结果
} ↑ |
|-- | ---------------------|
| |-----------|
↓ |
val result = session.push(value) // 此处得到 v.toResult() 的结果

Author

ForteScarlet

Inheritors

Types

Link copied to clipboard
interface Received<C, out T>

Properties

Link copied to clipboard
abstract override val coroutineContext: CoroutineContext

ContinuousSessionReceiver 作为 CoroutineScope 的协程上下文。 其中不会包含 Job

Functions

Link copied to clipboard
abstract suspend fun await(): SessionContinuation<C, T, R>

等待 ContinuousSessionProvider 的下一次 推送 结果, 并将此结果和 推送]ContinuousSessionProvider.push 处的挂起点打包为 SessionContinuation, 并在稍后通过 SessionContinuation.resumeSessionContinuation.resumeWithException 恢复。

abstract suspend fun await(result: R): ContinuousSessionReceiver.Received<C, T>

等待 ContinuousSessionProvider 的下一次 推送, 并在接收到时恢复一个结果 result

等待 ContinuousSessionProvider 的下一次 推送, 并在接收到时恢复一个由 result 计算的结果。

Inherited functions

Link copied to clipboard
suspend fun <C, T, R> ContinuousSessionReceiver<C, T, R>.awaitValue(result: R): T
Link copied to clipboard
inline suspend fun <C, T, R> ContinuousSessionReceiver<C, T, R>.awaitWith(block: (C, T) -> R)
Link copied to clipboard

进行多轮次处理。如果 block 的返回值类型不是 MultipleAwaitResult.Valid, 则 multipleAwaitWith 会继续 await 直到得到 MultipleAwaitResult.Valid 结果或产生了异常。