// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Threading.Tasks
{
/// Provides a set of static methods for configuring -related behaviors on asynchronous enumerables and disposables.
public static class TaskAsyncEnumerableExtensions
{
/// Configures how awaits on the tasks returned from an async disposable will be performed.
/// The source async disposable.
/// Whether to capture and marshal back to the current context.
/// The configured async disposable.
public static ConfiguredAsyncDisposable ConfigureAwait(this IAsyncDisposable source, bool continueOnCapturedContext) =>
new ConfiguredAsyncDisposable(source, continueOnCapturedContext);
/// Configures how awaits on the tasks returned from an async iteration will be performed.
/// The type of the objects being iterated.
/// The source enumerable being iterated.
/// Whether to capture and marshal back to the current context.
/// The configured enumerable.
public static ConfiguredCancelableAsyncEnumerable ConfigureAwait(
this IAsyncEnumerable source, bool continueOnCapturedContext) =>
new ConfiguredCancelableAsyncEnumerable(source, continueOnCapturedContext, cancellationToken: default);
/// Sets the to be passed to when iterating.
/// The type of the objects being iterated.
/// The source enumerable being iterated.
/// The to use.
/// The configured enumerable.
public static ConfiguredCancelableAsyncEnumerable WithCancellation(
this IAsyncEnumerable source, CancellationToken cancellationToken) =>
new ConfiguredCancelableAsyncEnumerable(source, continueOnCapturedContext: true, cancellationToken);
}
}