,System.Int32)} ,System.Int32,System.Reactive.Concurrency.IScheduler)} ,System.TimeSpan)} ,System.TimeSpan,System.Reactive.Concurrency.IScheduler)}
Observable.Take(IObservable, int) method¶
Defined in
Type: Observable
Namespace: System.Reactive.Linq
Assembly: System.Reactive.dll
Applies to
netstandard2.0
Overloads¶
- 1.
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count) - 2.
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count, IScheduler scheduler) - 3.
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration) - 4.
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
1. Overload¶
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count)
Summary: Returns a specified number of contiguous elements from the start of an observable sequence.
Type parameters
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | The sequence to take elements from. |
count | int | The number of elements to return. |
Returns: IObservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source is null. |
| System.ArgumentOutOfRangeException | count is less than zero. |
2. Overload¶
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count, IScheduler scheduler)
Summary: Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of Take(0).
Type parameters
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | The sequence to take elements from. |
count | int | The number of elements to return. |
scheduler | [IScheduler](# | Scheduler used to produce an OnCompleted message in case count is set to 0. |
Returns: IObservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or scheduler is null. |
| System.ArgumentOutOfRangeException | count is less than zero. |
3. Overload¶
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration)
Summary: Takes elements for the specified duration from the start of the observable source sequence.
Type parameters
| Name | Description |
|---|---|
TSource | The type of the elements in the source sequence. |
Parameters
| Name | Type | Description |
|---|---|---|
source | IObservable | Source sequence to take elements from. |
duration | TimeSpan | Duration for taking elements from the start of the sequence. |
Returns: IObservable
Remarks
Specifying a TimeSpan.Zero value for duration doesn't guarantee an empty sequence will be returned. This is a side-effect
of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute
immediately, despite the TimeSpan.Zero due time.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source is null. |
| System.ArgumentOutOfRangeException | duration is less than TimeSpan.Zero. |
4. Overload¶
public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, TimeSpan duration, IScheduler scheduler)
Summary: Takes elements for the specified duration from the start of the observable source sequence, 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 | IObservable | Source sequence to take elements from. |
duration | TimeSpan | Duration for taking elements from the start of the sequence. |
scheduler | [IScheduler](# | Scheduler to run the timer on. |
Returns: IObservable
Remarks
Specifying a TimeSpan.Zero value for duration doesn't guarantee an empty sequence will be returned. This is a side-effect
of the asynchrony introduced by the scheduler, where the action that stops forwarding callbacks from the source sequence may not execute
immediately, despite the TimeSpan.Zero due time.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | source or scheduler is null. |
| System.ArgumentOutOfRangeException | duration is less than TimeSpan.Zero. |