syncFromEvent
inline suspend fun <E : Event, R : Any> EventChannel<*>.syncFromEvent(priority: EventPriority = EventPriority.NORMAL, noinline mapper: suspend (E) -> R?): R
Content copied to clipboard
挂起当前协程, 监听事件 E, 并尝试从这个事件中获取一个值, 在超时时抛出 TimeoutCancellationException
Since
2.10
See also
本函数的异步版本
普通地监听一个事件
挂起当前协程, 并获取下一个事件实例
本函数的在超时后返回 null
的版本
Parameters
mapper
过滤转换器. 返回非 null 则代表得到了需要的值. syncFromEvent 会返回这个值
Throws
当 mapper 抛出任何异常时, 本函数会抛出该异常
Content copied to clipboard
挂起当前协程, 监听事件 E, 并尝试从这个事件中获取一个值, 在超时时抛出 TimeoutCancellationException
See also
本函数的异步版本
普通地监听一个事件
挂起当前协程, 并获取下一个事件实例
本函数的在超时后返回 null
的版本
Parameters
timeoutMillis
超时. 单位为毫秒.
mapper
过滤转换器. 返回非 null 则代表得到了需要的值. syncFromEvent 会返回这个值
Throws
kotlinx.coroutines.TimeoutCancellationException
在超时后抛出.
当 mapper 抛出任何异常时, 本函数会抛出该异常