Class WindowWhenOperator
The windowWhen operator.
public static class WindowWhenOperator
- Inheritance
-
System.ObjectWindowWhenOperator
Methods
WindowWhen<T, TBoundary>(Observable<T>, Func<Observable<TBoundary>>)
Branches out source's values as a nested Observable<T> that closes
(completing) and immediately reopens each time the observable returned by closingSelector
emits or completes. Mirrors rxjs's windowWhen. The first window opens eagerly at subscription time;
closingSelector is invoked again, and its result subscribed to afresh, every time a new
window opens.
public static Observable<Observable<T>> WindowWhen<T, TBoundary>(this Observable<T> source, Func<Observable<TBoundary>> closingSelector)
Parameters
sourceObservable<T>The source observable.
closingSelectorFunc<Observable<TBoundary>>Invoked (with no arguments) each time a window opens; the observable it returns closes that window on its first next or complete notification.
Returns
- Observable<Observable<T>>
An observable of windows, each itself an observable of the values collected during its lifetime.
Type Parameters
TThe element type of the source.
TBoundaryThe (unused) element type of the closing-notifier observable.
Remarks
Each closing-notifier subscription is torn down as soon as it produces its first signal (next or complete) —
built directly via Create<T>(Action<T>?, Action<Exception>?, Action?) assigned to its slot before subscribing (the
same pattern Take/First use — see their remarks), rather than a SingleAssignmentDisposable
reassigned only after Subscribe returns. This matters here specifically: a closing notifier that emits
and then completes synchronously (e.g. Observable.Of(1)) would otherwise reopen the window twice for a
single notifier, since both the synchronous next and the following complete would each trigger a
reopen before the naive wrapper-reassignment could take effect. Each closing-notifier subscriber is also
registered as a child of source's downstream subscriber (via Add(IDisposable))
before it is subscribed — see SubscribeChild<TSource, TResult>(Observable<TSource>, Subscriber<TResult>, Action<TSource>?, Action<Exception>?, Action?) — and
removed again as soon as it is superseded by the next cycle's, so a downstream disposal cascades into
whichever closing-notifier subscription is currently active instead of only the latest one leaking forever
as a dead entry in the downstream subscriber's finalizer list.