>,System.Func{--1,System.IObservable{--0}})}
Defined in Type: Observable
Namespace: System.Reactive.Linq
Assembly: System.Reactive.dll
Applies to
netstandard2.0
Overloads
- 1.
public static IObservable<TResult> Using<TResult, TResource>(Func<TResource> resourceFactory, Func<TResource, IObservable<TResult>> observableFactory) where TResource : IDisposable - 2.
public static IObservable<TResult> Using<TResult, TResource>(Func<CancellationToken, Task<TResource>> resourceFactoryAsync, Func<TResource, CancellationToken, Task<IObservable<TResult>>> observableFactoryAsync) where TResource : IDisposable
1. Overload
public static IObservable<TResult> Using<TResult, TResource>(Func<TResource> resourceFactory, Func<TResource, IObservable<TResult>> observableFactory) where TResource : IDisposable
Summary: Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime.
Type parameters
| Name | Description |
|---|---|
TResult | The type of the elements in the produced sequence. |
TResource | The type of the resource used during the generation of the resulting sequence. Needs to implement IDisposable. |
Parameters
| Name | Type | Description |
|---|---|---|
resourceFactory | Func | Factory function to obtain a resource object. |
observableFactory | Func | Factory function to obtain an observable sequence that depends on the obtained resource. |
Returns: IObservable
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | resourceFactory or observableFactory is null. |
2. Overload
public static IObservable<TResult> Using<TResult, TResource>(Func<CancellationToken, Task<TResource>> resourceFactoryAsync, Func<TResource, CancellationToken, Task<IObservable<TResult>>> observableFactoryAsync) where TResource : IDisposable
Summary: Constructs an observable sequence that depends on a resource object, whose lifetime is tied to the resulting observable sequence's lifetime. The resource is obtained and used through asynchronous methods. The CancellationToken passed to the asynchronous methods is tied to the returned disposable subscription, allowing best-effort cancellation at any stage of the resource acquisition or usage.
Type parameters
| Name | Description |
|---|---|
TResult | The type of the elements in the produced sequence. |
TResource | The type of the resource used during the generation of the resulting sequence. Needs to implement IDisposable. |
Parameters
| Name | Type | Description |
|---|---|---|
resourceFactoryAsync | Func | Asynchronous factory function to obtain a resource object. |
observableFactoryAsync | Func | Asynchronous factory function to obtain an observable sequence that depends on the obtained resource. |
Returns: IObservable
Remarks
When a subscription to the resulting sequence is disposed, the CancellationToken that was fed to the asynchronous resource factory and observable factory functions will be signaled.
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException | resourceFactoryAsync or observableFactoryAsync is null. |