Skip to content

)} ,System.Reactive.Concurrency.IScheduler)} ,System.Object)} ,System.Object,System.Reactive.Concurrency.IScheduler)} ,System.Threading.CancellationToken)} ,System.Threading.CancellationToken,System.Reactive.Concurrency.IScheduler)} ,System.Threading.CancellationToken,System.Object)} ,System.Threading.CancellationToken,System.Object,System.Reactive.Concurrency.IScheduler)}

TaskObservableExtensions.ToTask(IObservable) method

Defined in

Type: TaskObservableExtensions Namespace: System.Reactive.Threading.Tasks Assembly: System.Reactive.dll

Applies to

netstandard2.0

Overloads

  • 1. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable)
  • 2. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, IScheduler scheduler)
  • 3. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, object? state)
  • 4. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, object? state, IScheduler scheduler)
  • 5. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken)
  • 6. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, IScheduler scheduler)
  • 7. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, object? state)
  • 8. public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, object? state, IScheduler scheduler)

1. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable is null.

2. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, IScheduler scheduler)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
scheduler[IScheduler](#The scheduler used for overriding where the task completion signals will be issued.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable or scheduler is null.

3. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, object? state)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
stateobject?The state to use as the underlying task's AsyncState.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable is null.

4. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, object? state, IScheduler scheduler)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
stateobject?The state to use as the underlying task's AsyncState.
scheduler[IScheduler](#The scheduler used for overriding where the task completion signals will be issued.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable or scheduler is null.

5. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
cancellationTokenCancellationTokenCancellation token that can be used to cancel the task, causing unsubscription from the observable sequence.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable is null.

6. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, IScheduler scheduler)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
cancellationTokenCancellationTokenCancellation token that can be used to cancel the task, causing unsubscription from the observable sequence.
scheduler[IScheduler](#The scheduler used for overriding where the task completion signals will be issued.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable or scheduler is null.

7. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, object? state)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
cancellationTokenCancellationTokenCancellation token that can be used to cancel the task, causing unsubscription from the observable sequence.
stateobject?The state to use as the underlying task's AsyncState.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable is null.

8. Overload

public static Task<TResult> ToTask<TResult>(this IObservable<TResult> observable, CancellationToken cancellationToken, object? state, IScheduler scheduler)

Summary: Returns a task that will receive the last value or the exception produced by the observable sequence.

Type parameters

NameDescription
TResultThe type of the elements in the source sequence.

Parameters

NameTypeDescription
observableIObservableObservable sequence to convert to a task.
cancellationTokenCancellationTokenCancellation token that can be used to cancel the task, causing unsubscription from the observable sequence.
stateobject?The state to use as the underlying task's AsyncState.
scheduler[IScheduler](#The scheduler used for overriding where the task completion signals will be issued.

Returns: Task -- A task that will receive the last element or the exception produced by the observable sequence.

Exceptions

TypeCondition
System.ArgumentNullExceptionobservable or scheduler is null.