<PackageReference Include="System.Reactive" Version="6.0.0" />

TakeUntil<TSource>

sealed class TakeUntil<TSource> : Producer<TSource, _<TSource>>
using System.Reactive.Concurrency; using System.Reactive.Disposables; using System.Runtime.CompilerServices; namespace System.Reactive.Linq.ObservableImpl { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1 })] internal sealed class TakeUntil<[System.Runtime.CompilerServices.Nullable(2)] TSource> : Producer<TSource, TakeUntil<TSource>._> { [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal sealed class _ : IdentitySink<TSource> { private SingleAssignmentDisposableValue _timerDisposable; private int _wip; [System.Runtime.CompilerServices.Nullable(2)] private Exception _error; public _(IObserver<TSource> observer) : base(observer) { } public void Run(TakeUntil<TSource> parent) { _timerDisposable.Disposable = Scheduler.ScheduleAction<_>(parent._scheduler, this, parent._endTime, (Action<_>)delegate(_ state) { state.Tick(); }); Run(parent._source); } protected override void Dispose(bool disposing) { if (disposing) _timerDisposable.Dispose(); base.Dispose(disposing); } private void Tick() { OnCompleted(); } public override void OnNext(TSource value) { HalfSerializer.ForwardOnNext<TSource>((ISink<TSource>)this, value, ref _wip, ref _error); } public override void OnError(Exception error) { HalfSerializer.ForwardOnError<TSource>((ISink<TSource>)this, error, ref _wip, ref _error); } public override void OnCompleted() { HalfSerializer.ForwardOnCompleted<TSource>((ISink<TSource>)this, ref _wip, ref _error); } } private readonly IObservable<TSource> _source; private readonly DateTimeOffset _endTime; internal readonly IScheduler _scheduler; public TakeUntil(IObservable<TSource> source, DateTimeOffset endTime, IScheduler scheduler) { _source = source; _endTime = endTime; _scheduler = scheduler; } public IObservable<TSource> Combine(DateTimeOffset endTime) { if (_endTime <= endTime) return this; return new TakeUntil<TSource>(_source, endTime, _scheduler); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] protected override _ CreateSink(IObserver<TSource> observer) { return new _(observer); } protected override void Run([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 0 })] _ sink) { sink.Run(this); } } }