We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventChannel
逐渐弃用如下 8 个 top-level 函数:
nextEvent
nextEventAsync
nextEventOrNull
nextEventOrNullAsync
syncFromEvent
asyncFromEvent
syncFromEventOrNull
asyncFromEventOrNull
新增 2 个 EventChannel 的扩展函数 nextEvent 和 syncFromEvent:
public suspend inline fun <reified E : Event> EventChannel<*>.nextEvent( priority: EventPriority = EventPriority.NORMAL, noinline filter: suspend E.(E) -> Boolean = { true } ): E = coroutineScope { nextEventImpl(this@nextEvent, E::class, this@coroutineScope, priority, filter) } public suspend inline fun <reified E : Event, R : Any> EventChannel<*>.syncFromEvent( priority: EventPriority = EventPriority.NORMAL, crossinline mapper: suspend (E) -> R? // 删除了 receiver E ): R = coroutineScope { this@syncFromEvent.syncFromEventImpl(E::class, this, priority, mapper) }
注意, 默认的优先级为 NORMAL 而不是原来的 MONITOR
NORMAL
MONITOR
最终上述 8 个方法将简化为两个基础标准函数 (Extensions.kt) (见上 "变更").
超时, Async 和 OrNull 通过协程库的 CoroutineScope.async, withTimeout, withTimeoutOrNull 完成. 示例:
CoroutineScope.async
withTimeout
withTimeoutOrNull
withTimeout(3000) { GlobalEventChannel.nextEvent<MessageEvent>() } // 相当于原来的 syncFromEvent<MessageEvent>(3000)
EventChannel.nextEvent
EventChannel.syncFromEvent
The text was updated successfully, but these errors were encountered:
Deprecate no-receiver functions nextEvent*, syncFromEvent*, `asyn…
nextEvent*
syncFromEvent*
fc6f8ab
…cFromEvent*`. Add their `EventChannel`-receiver counterparts. #1827
731557a
f10cb0c
弃用无 receiver 的事件扩展函数, 增加其 EventChannel receiver 版本替换 (#1754)
701039e
* Deprecate no-receiver functions `nextEvent*`, `syncFromEvent*`, `asyncFromEvent*`. Add their `EventChannel`-receiver counterparts. #1827 * Fix migration * Migrate `nextMessage` to new API
弃用无 receiver 的事件扩展函数, 增加其 EventChannel receiver 版本替换 (mamoe#1754)
bb925fa
* Deprecate no-receiver functions `nextEvent*`, `syncFromEvent*`, `asyncFromEvent*`. Add their `EventChannel`-receiver counterparts. mamoe#1827 * Fix migration * Migrate `nextMessage` to new API
Successfully merging a pull request may close this issue.
动机
EventChannel
在 2.0 增加, 但原函数均不支持EventChannel
变更
弃用
逐渐弃用如下 8 个 top-level 函数:
nextEvent
nextEventAsync
nextEventOrNull
nextEventOrNullAsync
syncFromEvent
asyncFromEvent
syncFromEventOrNull
asyncFromEventOrNull
增加
新增 2 个
EventChannel
的扩展函数nextEvent
和syncFromEvent
:注意, 默认的优先级为
NORMAL
而不是原来的MONITOR
迁移方案
最终上述 8 个方法将简化为两个基础标准函数 (Extensions.kt) (见上 "变更").
超时, Async 和 OrNull 通过协程库的
CoroutineScope.async
,withTimeout
,withTimeoutOrNull
完成. 示例:自动迁移
nextEvent
: 替换为EventChannel.nextEvent
+withTimeout
nextEventAsync
: 无替换nextEventOrNull
: 替换为EventChannel.nextEvent
+withTimeoutOrNull
nextEventOrNullAsync
: 无替换syncFromEvent
: 替换为EventChannel.syncFromEvent
+withTimeout
asyncFromEvent
: 无替换syncFromEventOrNull
: 替换为EventChannel.syncFromEvent
+withTimeoutOrNull
asyncFromEventOrNull
: 无替换更新计划
EventChannel
receiver 版本替换 #1754)The text was updated successfully, but these errors were encountered: