>
Defined in Type: SignalAsync
Namespace: ReactiveUI.Primitives.Async
Assembly: ReactiveUI.Primitives.Async.Core.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, net471
public static IObservableAsync<T> Using<T, TResource>(Func<CancellationToken, ValueTask<TResource>> resourceFactory, Func<TResource, IObservableAsync<T>> signalFactory) where TResource : IAsyncDisposable
Summary: Creates an observable sequence that manages the lifetime of an asynchronous resource, ensuring the resource is disposed when the sequence terminates.
Type parameters
| Name | Description |
|---|---|
T | The type of the elements produced by the observable sequence. |
TResource | The type of the asynchronous resource that implements IAsyncDisposable. |
Parameters
| Name | Type | Description |
|---|---|---|
resourceFactory | Func | A function that asynchronously creates the resource to be used by the observable sequence. |
signalFactory | Func | A function that, given the created resource, returns an observable representing the signal sequence that uses the resource. |
Returns: IObservableAsync
Remarks
The resource is created for each subscription and is disposed asynchronously when the observable sequence terminates, either by completion or error. If the observable factory throws an exception, the resource is disposed before the exception is propagated. This method is useful for managing resources that must be disposed when no longer needed, such as streams or database connections, in conjunction with asynchronous observable sequences.