-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove System.Linq.Async dependency. (#19745)
- Loading branch information
1 parent
6aff518
commit e75dec1
Showing
4 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/AsyncPageableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters