Method Using
Using<TSource, TResource>(Func<TResource>, Func<TResource, IAsyncEnumerable<TSource>>)
Generates a sequence that's dependent on a resource object whose lifetime is determined by the sequence usage duration.
Declaration
public static IAsyncEnumerable<TSource> Using<TSource, TResource>(Func<TResource> resourceFactory, Func<TResource, IAsyncEnumerable<TSource>> enumerableFactory) where TResource : IAsyncDisposable
Parameters
| Type | Name | Description |
|---|---|---|
| Func<TResource> | resourceFactory | Resource factory function. |
| Func<TResource, IAsyncEnumerable<TSource>> | enumerableFactory | Enumerable factory function, having access to the obtained resource. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<TSource> | Sequence whose use controls the lifetime of the associated obtained resource. |
Type Parameters
| Name | Description |
|---|---|
| TSource | Source element type. |
| TResource | Resource type. |
Remarks
resourceFactory and enumerableFactory are evaluated lazily, once
enumeration has begun. The value returned by resourceFactory will be disposed after the
enumeration has completed.
The values returned by enumerableFactory and enumerableFactory are not
cached; multiple iterations of the IAsyncEnumerable<T> returned by this method will call these methods
separately for each iteration.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|