|
@@ -47,19 +47,33 @@ inline fun <T> Flow<T>.listen(
|
|
|
* @param event 销毁时机
|
|
|
* @param dispatcher 指定调度器
|
|
|
*/
|
|
|
+@Deprecated("规范命名", ReplaceWith("launchIn"))
|
|
|
@OptIn(InternalCoroutinesApi::class)
|
|
|
inline fun <T> Flow<T>.scope(
|
|
|
owner: LifecycleOwner? = null,
|
|
|
event: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
|
|
|
dispatcher: CoroutineDispatcher = Dispatchers.Main,
|
|
|
crossinline action: suspend CoroutineScope.(value: T) -> Unit
|
|
|
+): AndroidScope = launchIn(owner, event, dispatcher, action)
|
|
|
+
|
|
|
+/**
|
|
|
+ * Flow直接创建作用域
|
|
|
+ * @param owner 跟随的生命周期组件
|
|
|
+ * @param event 销毁时机
|
|
|
+ * @param dispatcher 指定调度器
|
|
|
+ */
|
|
|
+@OptIn(InternalCoroutinesApi::class)
|
|
|
+inline fun <T> Flow<T>.launchIn(
|
|
|
+ owner: LifecycleOwner? = null,
|
|
|
+ event: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
|
|
|
+ dispatcher: CoroutineDispatcher = Dispatchers.Main,
|
|
|
+ crossinline action: suspend CoroutineScope.(value: T) -> Unit
|
|
|
): AndroidScope = AndroidScope(owner, event, dispatcher).launch {
|
|
|
- this@scope.collect(object : FlowCollector<T> {
|
|
|
+ this@launchIn.collect(object : FlowCollector<T> {
|
|
|
override suspend fun emit(value: T) = action(this@launch, value)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 为EditText的输入框文本变化启用节流阀, 即超过指定时间后(默认800毫秒)的输入框文本变化事件[TextWatcher.onTextChanged]会被下游收集到
|
|
|
*
|