Skip to content

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> Use<TResource, T>(Func<CancellationToken, ValueTask<TResource>> resourceFactory, Func<TResource, IObservableAsync<T>> signalFactory) where TResource : IAsyncDisposable

View source

Summary: Creates an observable sequence that manages the lifetime of an asynchronous resource, ensuring the resource is disposed when the sequence terminates.

Type parameters

NameDescription
TResourceThe type of the asynchronous resource that implements IAsyncDisposable.
TThe type of the elements produced by the observable sequence.

Parameters

NameTypeDescription
resourceFactoryFunc>A function that asynchronously creates the resource to be used by the observable sequence. The function receives a CancellationToken and returns a ValueTask representing the asynchronous creation of the resource.
signalFactoryFunc>A function that, given the created resource, returns an observable representing the signal sequence that uses the resource.

Returns: IObservableAsync -- An observable that uses the specified resource and ensures the resource is disposed asynchronously when the sequence completes or an error occurs.