diff --git a/src/Azure/Azure.Quantum.Client/Authentication/CustomAccessTokenProvider.cs b/src/Azure/Azure.Quantum.Client/Authentication/CustomAccessTokenProvider.cs index dfc447c1bc5..b95e03237b1 100644 --- a/src/Azure/Azure.Quantum.Client/Authentication/CustomAccessTokenProvider.cs +++ b/src/Azure/Azure.Quantum.Client/Authentication/CustomAccessTokenProvider.cs @@ -81,7 +81,7 @@ static string GetTenantUriFromHeader(System.Net.Http.Headers.AuthenticationHeade /// A encapsulating the access token. public async Task GetAccessTokenAsync(CancellationToken cancellationToken) { - var application = applicationLazy.Value; + var application = await applicationLazy.Value; try { diff --git a/src/Azure/Azure.Quantum.Client/Utility/LazyAsync.cs b/src/Azure/Azure.Quantum.Client/Utility/LazyAsync.cs index 99f27d02124..5e978ff3ba9 100644 --- a/src/Azure/Azure.Quantum.Client/Utility/LazyAsync.cs +++ b/src/Azure/Azure.Quantum.Client/Utility/LazyAsync.cs @@ -9,36 +9,26 @@ namespace Microsoft.Azure.Quantum.Utility { - internal sealed class LazyAsync + internal sealed class LazyAsync : Lazy> { - private readonly Lazy> instance; - private readonly Lazy valueL; - /// - /// Constructor for use with synchronous factories + /// Initializes a new instance of the class. + /// Constructor for use with asynchronous factories. /// - public LazyAsync(Func synchronousFactory) - : this(new Lazy>(() => Task.Run(synchronousFactory))) - { - } + /// Async value factory. + public LazyAsync(Func> taskFactory) + : base(() => Task.Run(taskFactory)) + { } /// - /// Constructor for use with asynchronous factories + /// Initializes a new instance of the class. + /// Constructor for use with synchronous factories. /// - public LazyAsync(Func> asynchronousFactory) - : this(new Lazy>(() => asynchronousFactory())) - { - } - - // private constructor which sets both fields - private LazyAsync(Lazy> instance) - { - this.instance = instance; - this.valueL = new Lazy(() => this.instance.Value.GetAwaiter().GetResult()); - } - - public T Value => valueL.Value; + /// Sync value factory. + public LazyAsync(Func valueFactory) + : base(() => Task.Run(valueFactory)) + { } - public TaskAwaiter GetAwaiter() => instance.Value.GetAwaiter(); + public TaskAwaiter GetAwaiter() => Value.GetAwaiter(); } } \ No newline at end of file