是否有一个 Rx 框架函数可以创建一个可观察对象,该可观察对象在一段时间过去后结束?
有些可观察量就是如此需要。他们希望你倾听、倾听、倾听他们所说的一切,也许是永远!如果我真的只能处理几秒钟的事件怎么办?我可以写一些像
mouseMoves.TakeFor(TimeSpan.FromSeconds(2))
概念上的东西吗,这将创建一个主题,它将传递事件直到经过一定时间,然后取消订阅底层可观察并将其自己的序列标记为完成。我怀疑你可以用手这样写,但似乎必须有一些现有的运算符可以做到这一点。我曾希望 Observable.TimeOut 能够执行我想要的操作,例如使用
mouseMoves.Timeout(TimeSpan.FromSeconds(2), Observable.Empty<T>())
但我认为它所做的是如果观察之间的时间跨度长于可观察对象的超时时间给定值。这也很有用,但不完全是我所追求的。
Some observables are just so needy. They want you to listen and listen and listen to all they have to say, maybe for all of time! What if I can really only handle a few seconds' of events? Could I write something like
mouseMoves.TakeFor(TimeSpan.FromSeconds(2))
Conceptually, this would create a subject which would pass along events until a certain time had elapsed, then unsubscribe to the underlying observable and mark its own sequence complete. I suspect you could write it that way by hand, but it seems like there must be some existing operators which do this. I had hoped that Observable.TimeOut
would do what I want, e.g. using
mouseMoves.Timeout(TimeSpan.FromSeconds(2), Observable.Empty<T>())
But I think what it's doing is timing out the observable if the time span between observations is longer than the given value. This is useful, too, but not quite what I'm after.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要
TakeUntil
:Sounds like you need
TakeUntil
: