forwardToChannel

expect fun forwardToChannel(    channel: SendChannel<@UnsafeVariance BaseEvent>,     coroutineContext: CoroutineContext = EmptyCoroutineContext,     priority: EventPriority = EventPriority.MONITOR): Listener<@UnsafeVariance BaseEvent>

创建事件监听并将监听结果转发到 channel. 当 Channel.send 抛出 ClosedSendChannelException 时停止 Listener 监听和转发.

返回创建的会转发监听到的所有事件到 channel事件监听器. 停止 该监听器会停止转发, 不会影响目标 channel.

Channel.send 挂起, 则监听器也会挂起, 也就可能会导致事件广播过程挂起.

示例:

val eventChannel: EventChannel<BotEvent> = ...
val channel = Channel<BotEvent>() // kotlinx.coroutines.channels.Channel
eventChannel.forwardToChannel(channel, priority = ...)

// 其他地方
val event: BotEvent = channel.receive() // 挂起并接收一个事件

Since

2.10

See also

kotlinx.coroutines.channels.Channel
actual fun forwardToChannel(    channel: SendChannel<BaseEvent>,     coroutineContext: CoroutineContext,     priority: EventPriority): Listener<BaseEvent>

创建事件监听并将监听结果转发到 channel. 当 Channel.send 抛出 ClosedSendChannelException 时停止 Listener 监听和转发.

返回创建的会转发监听到的所有事件到 channel事件监听器. 停止 该监听器会停止转发, 不会影响目标 channel.

Channel.send 挂起, 则监听器也会挂起, 也就可能会导致事件广播过程挂起.

示例:

val eventChannel: EventChannel<BotEvent> = ...
val channel = Channel<BotEvent>() // kotlinx.coroutines.channels.Channel
eventChannel.forwardToChannel(channel, priority = ...)

// 其他地方
val event: BotEvent = channel.receive() // 挂起并接收一个事件

Since

2.10

See also

kotlinx.coroutines.channels.Channel