From e75dec15b8fc9a40886ed9daa98d8269db111382 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 23 Mar 2021 14:46:02 -0700 Subject: [PATCH] Remove System.Linq.Async dependency. (#19745) --- eng/Packages.Data.props | 1 - .../src/Azure.ResourceManager.Core.csproj | 1 - .../src/Extensions/AsyncPageableExtensions.cs | 37 +++++++++++++++++++ .../src/ResourceOperationsBase.cs | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/AsyncPageableExtensions.cs diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index bf10e24ba3fe2..31edab31cc0ca 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -72,7 +72,6 @@ - diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj index 0850e68ca8b06..d6ee2a51ea770 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Azure.ResourceManager.Core.csproj @@ -15,7 +15,6 @@ - diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/AsyncPageableExtensions.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/AsyncPageableExtensions.cs new file mode 100644 index 0000000000000..4f6ddb3e28aea --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/AsyncPageableExtensions.cs @@ -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 FirstOrDefaultAsync( + this AsyncPageable source, + Func 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; + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceOperationsBase.cs index b7f628c27e68b..429da52c7e4e2 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceOperationsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceOperationsBase.cs @@ -7,6 +7,7 @@ using System.Threading; using System.Threading.Tasks; using Azure.Core; +using Azure.ResourceManager.Core.Extensions; namespace Azure.ResourceManager.Core {