Replies: 2 comments 2 replies
-
I'll come back later with something more detailed if no one else gets to it first, but off the top of my head, it's primarily to do with circularity. The SliceSink needs to be able to dispose of the source Stream when its bounds are met, but the source Stream needs the SliceSink to create its own Disposable, and SettableDisposable works to facilitate this circularity. The differences between slice and skipAfter are semantic related, slice/skip/take manages when to accept or stop accepting events, and it's the best use of resources to dispose of the source stream after meeting the "take" boundary than to simply ignore the events. However that's exactly what |
Beta Was this translation helpful? Give feedback.
-
Ok, I see, so Perhaps one could add a little hint in the documentation? Because looking at the marble diagrams and the current description, I still have no idea why the difference though. The source stream gets disposed of in both cases at the same time. When Can you construct an example where that extended source stream lifetime of |
Beta Was this translation helpful? Give feedback.
-
I think #428 might be related to this behaviour.
Curious Behaviour
slice
,take
,takeWhile
(i.e.SliceSink
andTakeWhileSink
resp.) employ aSettableDisposable
and dispose the source stream themselves if the stop condition is met. They also forward theDisposable
to the run subscriber, to allow it to dispose the source on its own criteria.On the other hand
skipAfter
performs no disposing of the source itself, but only forwards the source'sDisposable
to the run subscriber, whose responsibility it then is to callDisposable.dispose()
onerror
or onend
.I could not trigger an unexpected behaviour from that. However it might be an issue in some edge cases?
Example
The example formulates a simple stream
A -- X |
, first usingtake
, second usingskipAfter
to end.Since
SettableDisposable
guards against double invocation, the source is disposed twice in theskipAfter
implementation.So, why the different source dispose strategies in the slice operators?
Beta Was this translation helpful? Give feedback.
All reactions