,System.Threading.CancellationToken)} ,System.DateTimeOffset)} ,System.DateTimeOffset,System.Reactive.Concurrency.IScheduler)} ,System.IObservable{--1})} ,System.Linq.Expressions.Expression})}
Qbservable.TakeUntil(IQbservable, CancellationToken) method¶
Defined in
Type: Qbservable
Namespace: System.Reactive.Linq
Assembly: System.Reactive.dll
Applies to
netstandard2.0
Overloads¶
- 1.
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, CancellationToken cancellationToken) - 2.
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, DateTimeOffset endTime) - 3.
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, DateTimeOffset endTime, IScheduler scheduler) - 4.
public static IQbservable<TSource> TakeUntil<TSource, TOther>(this IQbservable<TSource> source, IObservable<TOther> other) - 5.
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, Expression<Func<TSource, bool>> stopPredicate)
1. Overload¶
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source and result sequences. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IQbservable | The source sequence to relay elements of. |
cancellationToken | CancellationToken | The cancellation token to complete the target observable sequence on. |
Returns: IQbservablecancellationToken is cancelled.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source is csharp null . |
2. Overload¶
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, DateTimeOffset endTime)
Summary: Takes elements for the specified duration until the specified end time.
Type parameters
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IQbservable | Source sequence to take elements from. |
endTime | DateTimeOffset | Time 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: IQbservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source is null. |
3. Overload¶
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IQbservable | Source sequence to take elements from. |
endTime | DateTimeOffset | Time 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: IQbservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or scheduler is null. |
4. Overload¶
public static IQbservable<TSource> TakeUntil<TSource, TOther>(this IQbservable<TSource> source, IObservable<TOther> other)
Summary: Returns the elements from the source observable sequence until the other observable sequence produces an element.
Type parameters
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
TOther | The type of the elements in the other sequence that indicates the end of take behavior. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IQbservable | Source sequence to propagate elements for. |
other | IObservable | Observable sequence that terminates propagation of elements of the source sequence. |
Returns: IQbservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or other is null. |
5. Overload¶
public static IQbservable<TSource> TakeUntil<TSource>(this IQbservable<TSource> source, Expression<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
| Name | Description |
|---|---|
TSource | The type of the elements in the source and result sequences. |
Parameters
| Name | Type | Description |
|---|---|---|
source | [IQbservable | The source sequence to relay elements of. |
stopPredicate | Expression | Called after each upstream item has been emitted with that upstream item and should return csharp true to indicate the sequence should complete. |
Returns: IQbservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source 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);