Skip to content

})} })}

Qbservable.Switch(IQbservable>) method

Defined in

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

Applies to

netstandard2.0

Overloads

  • 1. public static IQbservable<TSource> Switch<TSource>(this IQbservable<IObservable<TSource>> sources)
  • 2. public static IQbservable<TSource> Switch<TSource>(this IQbservable<Task<TSource>> sources)

1. Overload

public static IQbservable<TSource> Switch<TSource>(this IQbservable<IObservable<TSource>> sources)

Summary: Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence. Each time a new inner observable sequence is received, unsubscribe from the previous inner observable sequence.

Type parameters

NameDescription
TSourceThe type of the elements in the source sequences.

Parameters

NameTypeDescription
sources[IQbservable>](#Observable sequence of inner observable sequences.

Returns: IQbservable -- The observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.

Exceptions

TypeCondition
System.ArgumentNullExceptionsources is null.

2. Overload

public static IQbservable<TSource> Switch<TSource>(this IQbservable<Task<TSource>> sources)

Summary: Transforms an observable sequence of tasks into an observable sequence producing values only from the most recent observable sequence. Each time a new task is received, the previous task's result is ignored.

Type parameters

NameDescription
TSourceThe type of the results produced by the source tasks.

Parameters

NameTypeDescription
sources[IQbservable>](#Observable sequence of tasks.

Returns: IQbservable -- The observable sequence that at any point in time produces the result of the most recent task that has been received.

Remarks

If the tasks support cancellation, consider manual conversion of the tasks using FromAsync, followed by a switch operation using Switch.

Exceptions

TypeCondition
System.ArgumentNullExceptionsources is null.