Skip to content

)} )} )}

ObservableAsync.ToObservableAsync(Task) method

Defined in

Type: ObservableAsync Namespace: ReactiveUI.Extensions.Async Assembly: ReactiveUI.Extensions.dll

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Overloads

  • 1. public static IObservableAsync<T> ToObservableAsync<T>(this Task<T> @this)
  • 2. public static IObservableAsync<Unit> ToObservableAsync(this Task @this)
  • 3. public static IObservableAsync<T> ToObservableAsync<T>(this IAsyncEnumerable<T> @this)
  • 4. public static IObservableAsync<T> ToObservableAsync<T>(this IEnumerable<T> @this)

1. Overload

public static IObservableAsync<T> ToObservableAsync<T>(this Task<T> @this)

View source

Summary: Converts a task representing a single asynchronous value into an observable sequence that emits the result when the task completes.

Type parameters

NameDescription
TThe type of the value produced by the task and emitted by the observable sequence.

Parameters

NameTypeDescription
thisTaskThe task to convert to an asynchronous observable sequence. Cannot be null.

Returns: IObservableAsync -- An asynchronous observable sequence that emits the result of the task when it completes, followed by a completion notification.

Remarks

The returned observable will emit the task's result and then complete. If the task is canceled or fails, the observable will propagate the corresponding error. The task is awaited in the background, and cancellation is supported via the observable's subscription.

2. Overload

public static IObservableAsync<Unit> ToObservableAsync(this Task @this)

View source

Summary: Converts the specified task into an asynchronous observable sequence that signals completion when the task finishes.

Parameters

NameTypeDescription
thisTaskThe task to be observed. Cannot be null.

Returns: IObservableAsync -- An asynchronous observable sequence that emits a single value when the task completes successfully, followed by a completion notification.

Remarks

The returned observable emits a single unit value upon task completion and then signals completion. If the task is canceled or fails, the observable will propagate the corresponding error. This method is useful for integrating task-based operations into observable workflows.

3. Overload

public static IObservableAsync<T> ToObservableAsync<T>(this IAsyncEnumerable<T> @this)

View source

Summary: Converts an asynchronous enumerable sequence to an asynchronous observable sequence.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
thisIAsyncEnumerableThe asynchronous enumerable sequence to convert. Cannot be null.

Returns: IObservableAsync -- An asynchronous observable sequence that emits the elements of the source sequence.

Remarks

The returned observable emits each element from the source sequence as it is produced and signals completion when the source sequence ends. Cancellation is supported via the observer's cancellation token.

4. Overload

public static IObservableAsync<T> ToObservableAsync<T>(this IEnumerable<T> @this)

View source

Summary: Converts the specified enumerable sequence to an asynchronous observable sequence, emitting each element in the background.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
thisIEnumerableThe enumerable sequence to convert to an asynchronous observable. Cannot be null.

Returns: IObservableAsync -- An asynchronous observable sequence that emits each element from the source enumerable and completes when all elements have been emitted.

Remarks

The returned observable emits items on a background thread. Cancellation is supported via the observer's cancellation token. If the source sequence is empty, the observable completes immediately.