rxjs - Rx - How to apply to stream distinctUntilChanged that allows emit duplicate item after some period?
问题描述
So, I have to implement some chain or perhaps some custom RxJava operator to an Observable, that will distinct items emitted from Observable, until they change, but only for some short period (like 1 sec), then duplicated item can be emitted again.
What I need is some nested combination of distinctUntilChanged, with throttle?
Main requirements are:
- different items have to be emitted without any delay
- the same item can not be emitted twice in given period
I couldn't find any operator that matches my requirement so, probably I'll need to write some custom Rx operator, but still I can't figure out how to start
解决方案
您只需使用运算符即可完成此groupBy
操作。由于每个都通过group$
管道传输,throttleTime
并且每个发射都通过这个group$
Observable,因此它将忽略所有后续发射 1s:
source$
.pipe(
groupBy(item => item.whatever),
mergeMap(group$ => group$.pipe(
throttleTime(1000)
)),
)
.subscribe(...);
推荐阅读
- spring-data-jpa - 在 Spring Boot 中使用 Kafka 和 Postgres 进行 SAGA 和本地事务
- bash - 如何在 bash 命令行参数范围内进行搜索
- angular - 使用动态对象数据在角度模板中显示对象数据
- c# - 我是否使用继承违反了 SRP?
- python - 分出子流程作业
- python - 删除数据框列中的非字母 str
- python - 如何使用气流 ssh_operator 执行 nohup 命令?
- python - 使用 grpc 和 cloud-datastore 时如何修复 App Engine Flex 中的 AttributeError?
- sql-server-2012 - SSRS 集团小计和总计
- python - 可以将维度传递给 XArray 数据集中的变量吗?