Skip to content

Commit 6af7491

Browse files
authored
Generate .ConfigureAwait(false) for AsyncPageableWrapper (Azure#51574)
* Generate `.ConfigureAwait(false)` for AsyncPageableWrapper * refine * refine
1 parent 0f2498f commit 6af7491

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/Providers/PageableWrapperProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using System;
5-
using System.Collections.Generic;
6-
using System.IO;
74
using Microsoft.TypeSpec.Generator.Primitives;
85
using Microsoft.TypeSpec.Generator.Providers;
96
using Microsoft.TypeSpec.Generator.Statements;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
10+
using System.Threading.Tasks;
1011
using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
1112

1213
namespace Azure.Generator.Management.Providers
@@ -124,10 +125,15 @@ private MethodProvider BuildAsPagesMethod()
124125

125126
// Build the method body using foreach and yield return pattern
126127
var pageType = new CSharpType(typeof(Page<>), _tType);
128+
var asPagesInvocation = _sourceField.Invoke("AsPages", [continuationTokenParam, pageSizeHintParam]);
129+
var pages = _isAsync
130+
// we can't write ConfigureAwait for a non-async invoke, this is a workaround
131+
? asPagesInvocation.Invoke(nameof(TaskAsyncEnumerableExtensions.ConfigureAwait), [False], null, false, false, extensionType: typeof(TaskAsyncEnumerableExtensions))
132+
: asPagesInvocation;
127133
var foreachStatement = new ForEachStatement(
128134
pageType,
129135
"page",
130-
_sourceField.Invoke("AsPages", [continuationTokenParam, pageSizeHintParam]),
136+
pages,
131137
isAsync: _isAsync,
132138
out var pageVar);
133139

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/AsyncPageableWrapper.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)