Table of Contents

Class AsyncBridge

Namespace
RxSharp
Assembly
RxSharp.dll

Bridges an Observable<T> to a Task<T>. Mirrors rxjs's firstValueFrom/lastValueFrom.

public static class AsyncBridge
Inheritance
System.Object
AsyncBridge

Methods

FirstValueFrom<T>(Observable<T>)

Subscribes to source and returns a task that completes with its first emitted value, then unsubscribes. Faults with EmptyErrorException if the source completes without emitting.

public static Task<T> FirstValueFrom<T>(this Observable<T> source)

Parameters

source Observable<T>

The observable to take the first value from.

Returns

Task<T>

A task that resolves to the source's first value.

Type Parameters

T

The element type of the source.

FirstValueFrom<T>(Observable<T>, T)

Subscribes to source and returns a task that completes with its first emitted value, then unsubscribes. Resolves to defaultValue instead of faulting if the source completes without emitting.

public static Task<T> FirstValueFrom<T>(this Observable<T> source, T defaultValue)

Parameters

source Observable<T>

The observable to take the first value from.

defaultValue T

The value to resolve with if the source completes without emitting.

Returns

Task<T>

A task that resolves to the source's first value, or defaultValue.

Type Parameters

T

The element type of the source.

LastValueFrom<T>(Observable<T>)

Subscribes to source and returns a task that completes with its last emitted value once the source completes. Faults with EmptyErrorException if the source completes without ever emitting.

public static Task<T> LastValueFrom<T>(this Observable<T> source)

Parameters

source Observable<T>

The observable to take the last value from.

Returns

Task<T>

A task that resolves to the source's last value once it completes.

Type Parameters

T

The element type of the source.

LastValueFrom<T>(Observable<T>, T)

Subscribes to source and returns a task that completes with its last emitted value once the source completes. Resolves to defaultValue instead of faulting if the source completes without ever emitting.

public static Task<T> LastValueFrom<T>(this Observable<T> source, T defaultValue)

Parameters

source Observable<T>

The observable to take the last value from.

defaultValue T

The value to resolve with if the source completes without emitting.

Returns

Task<T>

A task that resolves to the source's last value, or defaultValue.

Type Parameters

T

The element type of the source.