Skip to content

Commit

Permalink
Remove System.Linq.Async dependency. (#19745)
Browse files Browse the repository at this point in the history
  • Loading branch information
allenjzhang authored Mar 23, 2021
1 parent 6aff518 commit e75dec1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 0 additions & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<PackageReference Update="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" />
<PackageReference Update="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Update="System.Collections.Immutable" Version="1.3.1" />
<PackageReference Update="System.Linq.Async" Version="4.0.0" />

<!-- Azure SDK packages -->
<PackageReference Update="Azure.Core" Version="1.10.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<ItemGroup>
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="Azure.ResourceManager.Resources" />
<PackageReference Include="System.Linq.Async" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Azure.ResourceManager.Core.Extensions
{
internal static class AsyncPageableExtensions
{
public static async Task<TSource> FirstOrDefaultAsync<TSource>(
this AsyncPageable<TSource> source,
Func<TSource, bool> predicate,
CancellationToken token = default)
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (predicate == null)
throw new ArgumentNullException(nameof(predicate));

token.ThrowIfCancellationRequested();

await foreach (var item in source.ConfigureAwait(false))
{
token.ThrowIfCancellationRequested();

if (predicate(item))
{
return item;
}
}

return default;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
using Azure.ResourceManager.Core.Extensions;

namespace Azure.ResourceManager.Core
{
Expand Down

0 comments on commit e75dec1

Please sign in to comment.