Skip to content

,System.IObservable{--1})} ,System.Func{--0,System.Boolean})} ,System.Threading.CancellationToken)} ,System.DateTimeOffset)} ,System.DateTimeOffset,System.Reactive.Concurrency.IScheduler)}

Observable.TakeUntil(IObservable, IObservable) method

Defined in

Type: Observable Namespace: System.Reactive.Linq Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static IObservable<TSource> TakeUntil<TSource, TOther>(this IObservable<TSource> source, IObservable<TOther> other)
  • 2. public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, Func<TSource, bool> stopPredicate)
  • 3. public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, CancellationToken cancellationToken)
  • 4. public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime)
  • 5. public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime, IScheduler scheduler)

1. Overload

public static IObservable<TSource> TakeUntil<TSource, TOther>(this IObservable<TSource> source, IObservable<TOther> other)

Summary: Returns the elements from the source observable sequence until the other observable sequence produces an element.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.
TOtherThe type of the elements in the other sequence that indicates the end of take behavior.

Parameters

NameTypeDescription
sourceIObservableSource sequence to propagate elements for.
otherIObservableObservable sequence that terminates propagation of elements of the source sequence.

Returns: IObservable -- An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or other is null.

2. Overload

public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, Func<TSource, bool> stopPredicate)

Summary: Relays elements from the source observable sequence and calls the predicate after an emission to check if the sequence should stop after that specific item.

Type parameters

NameDescription
TSourceThe type of the elements in the source and result sequences.

Parameters

NameTypeDescription
sourceIObservableThe source sequence to relay elements of.
stopPredicateFuncCalled after each upstream item has been emitted with that upstream item and should return csharp true to indicate the sequence should complete.

Returns: IObservable -- The observable sequence with the source elements until the stop predicate returns true.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or stopPredicate is csharp null .

Examples

The following sequence will stop after the value 5 has been encountered:

Observable.Range(1, 10)
 .TakeUntil(item => item == 5)
 .Subscribe(Console.WriteLine);

3. Overload

public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, CancellationToken cancellationToken)

Summary: Relays elements from the source observable sequence until the provided cancellationToken is cancelled. Completes immediately if the provided cancellationToken is already cancelled upon subscription.

Type parameters

NameDescription
TSourceThe type of the elements in the source and result sequences.

Parameters

NameTypeDescription
sourceIObservableThe source sequence to relay elements of.
cancellationTokenCancellationTokenThe cancellation token to complete the target observable sequence on.

Returns: IObservable -- The observable sequence with the source elements until the provided cancellationToken is cancelled.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is csharp null .

4. Overload

public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime)

Summary: Takes elements for the specified duration until the specified end time.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to take elements from.
endTimeDateTimeOffsetTime to stop taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, the result stream will complete immediately.

Returns: IObservable -- An observable sequence with the elements taken until the specified end time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource is null.

5. Overload

public static IObservable<TSource> TakeUntil<TSource>(this IObservable<TSource> source, DateTimeOffset endTime, IScheduler scheduler)

Summary: Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequence.

Parameters

NameTypeDescription
sourceIObservableSource sequence to take elements from.
endTimeDateTimeOffsetTime to stop taking elements from the source sequence. If this value is less than or equal to DateTimeOffset.UtcNow, the result stream will complete immediately.
scheduler[IScheduler](#Scheduler to run the timer on.

Returns: IObservable -- An observable sequence with the elements taken until the specified end time.

Exceptions

TypeCondition
System.ArgumentNullExceptionsource or scheduler is null.