Skip to content

Commit

Permalink
Rename to Await
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Mar 7, 2018
1 parent 3819d3d commit d2857e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions MoreLinq.Test/NullArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public System.Linq.IOrderedEnumerable<T> CreateOrderedEnumerable<TKey>(Func<T, T

#if !NO_ASYNC

public class SelectAsyncEnumerable<T> : Enumerable<T>,
Experimental.ISelectAsyncEnumerable<T>
public class AwaitQuery<T> : Enumerable<T>,
Experimental.IAwaitQuery<T>
{
public Experimental.SelectAsyncOptions Options => Experimental.SelectAsyncOptions.Default;
public Experimental.ISelectAsyncEnumerable<T> WithOptions(Experimental.SelectAsyncOptions options) => this;
public Experimental.AwaitQueryOptions Options => Experimental.AwaitQueryOptions.Default;
public Experimental.IAwaitQuery<T> WithOptions(Experimental.AwaitQueryOptions options) => this;
}

#endif
Expand Down
74 changes: 37 additions & 37 deletions MoreLinq/Experimental/SelectAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ namespace MoreLinq.Experimental
/// Represents options for an asynchronous projection operation.
/// </summary>

public sealed class SelectAsyncOptions
public sealed class AwaitQueryOptions
{
/// <summary>
/// The default options an asynchronous projection operation.
/// </summary>

public static readonly SelectAsyncOptions Default =
new SelectAsyncOptions(null /* = unbounded concurrency */,
TaskScheduler.Default,
preserveOrder: false);
public static readonly AwaitQueryOptions Default =
new AwaitQueryOptions(null /* = unbounded concurrency */,
TaskScheduler.Default,
preserveOrder: false);

/// <summary>
/// Gets a positive (non-zero) integer that specifies the maximum
Expand All @@ -65,7 +65,7 @@ public sealed class SelectAsyncOptions

public bool PreserveOrder { get; }

SelectAsyncOptions(int? maxConcurrency, TaskScheduler scheduler, bool preserveOrder)
AwaitQueryOptions(int? maxConcurrency, TaskScheduler scheduler, bool preserveOrder)
{
MaxConcurrency = maxConcurrency == null || maxConcurrency > 0
? maxConcurrency
Expand All @@ -84,8 +84,8 @@ public sealed class SelectAsyncOptions
/// Use <c>null</c> to mean unbounded concurrency.</param>
/// <returns>Options with the new setting.</returns>

public SelectAsyncOptions WithMaxConcurrency(int? value) =>
value == MaxConcurrency ? this : new SelectAsyncOptions(value, Scheduler, PreserveOrder);
public AwaitQueryOptions WithMaxConcurrency(int? value) =>
value == MaxConcurrency ? this : new AwaitQueryOptions(value, Scheduler, PreserveOrder);

/// <summary>
/// Returns new options with the given scheduler.
Expand All @@ -94,8 +94,8 @@ public SelectAsyncOptions WithMaxConcurrency(int? value) =>
/// The scheduler to use to for the workhorse task.</param>
/// <returns>Options with the new setting.</returns>

public SelectAsyncOptions WithScheduler(TaskScheduler value) =>
value == Scheduler ? this : new SelectAsyncOptions(MaxConcurrency, value, PreserveOrder);
public AwaitQueryOptions WithScheduler(TaskScheduler value) =>
value == Scheduler ? this : new AwaitQueryOptions(MaxConcurrency, value, PreserveOrder);

/// <summary>
/// Returns new options with the given Boolean indicating whether or
Expand All @@ -108,8 +108,8 @@ public SelectAsyncOptions WithScheduler(TaskScheduler value) =>
/// efficiency.</param>
/// <returns>Options with the new setting.</returns>

public SelectAsyncOptions WithPreserveOrder(bool value) =>
value == PreserveOrder ? this : new SelectAsyncOptions(MaxConcurrency, Scheduler, value);
public AwaitQueryOptions WithPreserveOrder(bool value) =>
value == PreserveOrder ? this : new AwaitQueryOptions(MaxConcurrency, Scheduler, value);
}

/// <summary>
Expand All @@ -118,13 +118,13 @@ public SelectAsyncOptions WithPreserveOrder(bool value) =>
/// <inheritdoc />
/// <typeparam name="T">The type of the source elements.</typeparam>

public interface ISelectAsyncEnumerable<out T> : IEnumerable<T>
public interface IAwaitQuery<out T> : IEnumerable<T>
{
/// <summary>
/// The options to apply to this asynchronous projection operation.
/// </summary>

SelectAsyncOptions Options { get; }
AwaitQueryOptions Options { get; }

/// <summary>
/// Returns a new asynchronous projection operation that will use the
Expand All @@ -135,7 +135,7 @@ public interface ISelectAsyncEnumerable<out T> : IEnumerable<T>
/// Returns a new sequence that projects asynchronously using the
/// supplied options.</returns>

ISelectAsyncEnumerable<T> WithOptions(SelectAsyncOptions options);
IAwaitQuery<T> WithOptions(AwaitQueryOptions options);
}

static partial class ExperimentalEnumerable
Expand All @@ -148,7 +148,7 @@ static partial class ExperimentalEnumerable
/// <param name="source">The source sequence.</param>
/// <returns>The converted sequence.</returns>

public static IEnumerable<T> AsSequential<T>(this ISelectAsyncEnumerable<T> source) =>
public static IEnumerable<T> AsSequential<T>(this IAwaitQuery<T> source) =>
source.MaxConcurrency(1);

/// <summary>
Expand All @@ -162,7 +162,7 @@ public static IEnumerable<T> AsSequential<T>(this ISelectAsyncEnumerable<T> sour
/// A sequence that projects results asynchronously using the given
/// concurrency limit.</returns>

public static ISelectAsyncEnumerable<T> MaxConcurrency<T>(this ISelectAsyncEnumerable<T> source, int value) =>
public static IAwaitQuery<T> MaxConcurrency<T>(this IAwaitQuery<T> source, int value) =>
source.WithOptions(source.Options.WithMaxConcurrency(value));

/// <summary>
Expand All @@ -175,7 +175,7 @@ public static ISelectAsyncEnumerable<T> MaxConcurrency<T>(this ISelectAsyncEnume
/// A sequence that projects results asynchronously using no defined
/// limitation on concurrency.</returns>

public static ISelectAsyncEnumerable<T> UnboundedConcurrency<T>(this ISelectAsyncEnumerable<T> source) =>
public static IAwaitQuery<T> UnboundedConcurrency<T>(this IAwaitQuery<T> source) =>
source.WithOptions(source.Options.WithMaxConcurrency(null));

/// <summary>
Expand All @@ -189,7 +189,7 @@ public static ISelectAsyncEnumerable<T> UnboundedConcurrency<T>(this ISelectAsyn
/// A sequence that projects results asynchronously using the given
/// scheduler.</returns>

public static ISelectAsyncEnumerable<T> Scheduler<T>(this ISelectAsyncEnumerable<T> source, TaskScheduler value)
public static IAwaitQuery<T> Scheduler<T>(this IAwaitQuery<T> source, TaskScheduler value)
{
if (source == null) throw new ArgumentNullException(nameof(source));
if (value == null) throw new ArgumentNullException(nameof(value));
Expand All @@ -210,7 +210,7 @@ public static ISelectAsyncEnumerable<T> Scheduler<T>(this ISelectAsyncEnumerable
/// results will be yielded in order.
/// </remarks>

public static ISelectAsyncEnumerable<T> AsOrdered<T>(this ISelectAsyncEnumerable<T> source) =>
public static IAwaitQuery<T> AsOrdered<T>(this IAwaitQuery<T> source) =>
PreserveOrder(source, true);

/// <summary>
Expand All @@ -225,7 +225,7 @@ public static ISelectAsyncEnumerable<T> AsOrdered<T>(this ISelectAsyncEnumerable
/// guarantee of returning results in the order of the source
/// sequence.</returns>

public static ISelectAsyncEnumerable<T> AsUnordered<T>(this ISelectAsyncEnumerable<T> source) =>
public static IAwaitQuery<T> AsUnordered<T>(this IAwaitQuery<T> source) =>
PreserveOrder(source, false);

/// <summary>
Expand All @@ -244,7 +244,7 @@ public static ISelectAsyncEnumerable<T> AsUnordered<T>(this ISelectAsyncEnumerab
/// results order or unordered based on
/// <paramref name="value"/>.</returns>

public static ISelectAsyncEnumerable<T> PreserveOrder<T>(this ISelectAsyncEnumerable<T> source, bool value) =>
public static IAwaitQuery<T> PreserveOrder<T>(this IAwaitQuery<T> source, bool value) =>
source.WithOptions(source.Options.WithPreserveOrder(value));

/// <summary>
Expand Down Expand Up @@ -272,10 +272,10 @@ public static ISelectAsyncEnumerable<T> PreserveOrder<T>(this ISelectAsyncEnumer
/// that some tasks will be wasted, those that are in flight.</para>
/// </remarks>

public static ISelectAsyncEnumerable<T> Await<T>(
public static IAwaitQuery<T> Await<T>(
this IEnumerable<Task<T>> source)
{
return source.SelectAsync((e, _) => e);
return source.Await((e, _) => e);
}

/// <summary>
Expand Down Expand Up @@ -313,7 +313,7 @@ public static ISelectAsyncEnumerable<T> Await<T>(
/// thread-agnostic.</para>
/// </remarks>

public static ISelectAsyncEnumerable<TResult> SelectAsync<T, TResult>(
public static IAwaitQuery<TResult> Await<T, TResult>(
this IEnumerable<T> source, Func<T, CancellationToken, Task<TResult>> selector)
{
if (source == null) throw new ArgumentNullException(nameof(source));
Expand Down Expand Up @@ -522,30 +522,30 @@ static async Task CollectToAsync<T, TResult, TNotice>(

static class SelectAsyncEnumerable
{
public static ISelectAsyncEnumerable<T>
public static IAwaitQuery<T>
Create<T>(
Func<SelectAsyncOptions, IEnumerable<T>> impl,
SelectAsyncOptions options = null) =>
new SelectAsyncEnumerable<T>(impl, options);
Func<AwaitQueryOptions, IEnumerable<T>> impl,
AwaitQueryOptions options = null) =>
new AwaitQuery<T>(impl, options);
}

sealed class SelectAsyncEnumerable<T> : ISelectAsyncEnumerable<T>
sealed class AwaitQuery<T> : IAwaitQuery<T>
{
readonly Func<SelectAsyncOptions, IEnumerable<T>> _impl;
readonly Func<AwaitQueryOptions, IEnumerable<T>> _impl;

public SelectAsyncEnumerable(Func<SelectAsyncOptions, IEnumerable<T>> impl,
SelectAsyncOptions options = null)
public AwaitQuery(Func<AwaitQueryOptions, IEnumerable<T>> impl,
AwaitQueryOptions options = null)
{
_impl = impl;
Options = options ?? SelectAsyncOptions.Default;
Options = options ?? AwaitQueryOptions.Default;
}

public SelectAsyncOptions Options { get; }
public AwaitQueryOptions Options { get; }

public ISelectAsyncEnumerable<T> WithOptions(SelectAsyncOptions options)
public IAwaitQuery<T> WithOptions(AwaitQueryOptions options)
{
if (options == null) throw new ArgumentNullException(nameof(options));
return Options == options ? this : new SelectAsyncEnumerable<T>(_impl, options);
return Options == options ? this : new AwaitQuery<T>(_impl, options);
}

public IEnumerator<T> GetEnumerator() => _impl(Options).GetEnumerator();
Expand Down

0 comments on commit d2857e8

Please sign in to comment.