简体   繁体   English

发出新值时删除操作

[英]Drop operations when new value is emitted

Is there a way to drop all operations on a flow that is being collected when a new value is emitted, so that the new value gets to be processed while the old one is dropped and not processed further down the flow once the new value is emitted?有没有办法在发出新值时丢弃正在收集的流上的所有操作,以便在发出新值时处理新值而丢弃旧值并且不会在发出新值后在流中进一步处理?

I believe you're looking for Flow.collectLatest我相信您正在寻找 Flow.collectLatest

kotlinx.coroutines.flow/collect-latest kotlinx.coroutines.flow/collect-latest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RxJava - 如何在发出新项目时停止正在运行的任务 - RxJava - How to stop a running task when new item emitted 如何从第一个可观测值获得发射值 - How to get emitted value from first observable 如何跳过流并仅发送最后发出的值 - How to skip a Flow and just send last emitted value 将行复制到另一个表时删除或转换复制的值 - Drop or convert copied value when copying row to another table 定期发出最后一个值的流,当一个新值到达时 - Flow that emits the last value periodically, and when a new value arrives 当新值与上一个值相同时,StateFlow 不会发出 - StateFlow don't emit when the new value same last value 附加新值时不会调用列表设置器 - List setter is not being called when appending a new value 即使一个或多个操作抛出异常,如何继续多个 Kotlin 协程异步操作? - How to continue multiple Kotlin Coroutines async operations even when one or more operations throw an exception? 使用 ViewModel 重新创建 Fragments 时如何执行一次提取操作 - How to do one time fetch operations when Fragments are recreated with ViewModel 为什么国家不能<T>变量在分配新值时触发 UI 更新? - Why can't a State<T> variable fire UI update when it is assigned by a new value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM