Reactive Extension Operator SkipLast 如何工作?

How does Reactive Extension Operator SkipLast work?

在 Reactivex.IO 文档中指出

You can ignore the final n items emitted by an Observable and attend only to those items that come before them, by modifying the Observable with the SkipLast operator.

以及来自 http://reactivex.io/documentation/operators/skiplast.html 的图表

我的期望:SkipLast 将读取整个 Observable,直到它满足 OnCompleted,然后生成一个新的 Observable,其计时与原始 Observable 相同,但跳过最后一个。

我的疑问:SkipLast 操作员如何知道“3”是 Observable 中的最后 2 项?没有看到 OnCompleted 怎么知道最后第 n 个项目?

感谢@PanagiotisKanavos、@akarnokd 的宝贵意见。

它在内部使用固定大小的队列实现。从序列中取出项目并将它们排入队列,当队列已满并开始溢出时,将项目出队并入队最新值并发送到 OnNext(dequeued_value),因此当达到 OnCompleted 时,您将不会发送缓存的项目并调用 OnCompleted。最后 N 个缓存项被跳过。

如果使用 skipLast(N) 来自 source code,则 N 消息将保存在 this._ring 数组中。一旦 N+1 到达,第一个消息被发出,N+2 到达 => 第二个消息被发出等