Skip to content

Commit 9cef8d5

Browse files
Remove CancellationToken.
1 parent d11b0e0 commit 9cef8d5

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

src/ResourceManager/Common/Commands.Common.Strategies.UnitTest/AsyncCmdletExtensionsTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Rest;
55
using Xunit;
66
using Microsoft.WindowsAzure.Commands.ScenarioTest;
7+
using System.Threading;
78

89
namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest
910
{
@@ -48,6 +49,9 @@ public async Task<ResourceConfig<RG>> CreateConfigAsync()
4849

4950
class AsyncCmdlet : IAsyncCmdlet
5051
{
52+
public CancellationToken CancellationToken { get; }
53+
= new CancellationToken();
54+
5155
public IEnumerable<KeyValuePair<string, object>> Parameters
5256
{
5357
get
@@ -93,7 +97,7 @@ public async Task TestVerboseStream()
9397
var parameters = new Parameters();
9498
var asyncCmdlet = new AsyncCmdlet();
9599

96-
await client.RunAsync("subscriptionId", parameters, asyncCmdlet, new System.Threading.CancellationToken());
100+
await client.RunAsync("subscriptionId", parameters, asyncCmdlet);
97101
}
98102
}
99103
}

src/ResourceManager/Common/Commands.Common.Strategies/AsyncCmdletExtensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ public static async Task<TModel> RunAsync<TModel>(
4646
this IClient client,
4747
string subscriptionId,
4848
IParameters<TModel> parameters,
49-
IAsyncCmdlet asyncCmdlet,
50-
CancellationToken cancellationToken)
49+
IAsyncCmdlet asyncCmdlet)
5150
where TModel : class
5251
{
5352
// create a DAG of configs.
5453
var config = await parameters.CreateConfigAsync();
5554
// read current Azure state.
56-
var current = await config.GetStateAsync(client, cancellationToken);
55+
var current = await config.GetStateAsync(client, asyncCmdlet.CancellationToken);
5756
// update location.
5857
parameters.Location = current.UpdateLocation(parameters.Location, config);
5958
// update a DAG of configs.
@@ -71,7 +70,7 @@ public static async Task<TModel> RunAsync<TModel>(
7170
var newState = await config.UpdateStateAsync(
7271
client,
7372
target,
74-
cancellationToken,
73+
asyncCmdlet.CancellationToken,
7574
new ShouldProcess(asyncCmdlet),
7675
asyncCmdlet.ReportTaskProgress);
7776
// return a resource model
@@ -185,6 +184,9 @@ sealed class AsyncCmdlet : IAsyncCmdlet
185184
public IEnumerable<KeyValuePair<string, object>> Parameters
186185
=> Cmdlet.Parameters;
187186

187+
public CancellationToken CancellationToken { get; }
188+
= new CancellationToken();
189+
188190
public AsyncCmdlet(ICmdlet cmdlet)
189191
{
190192
Cmdlet = cmdlet;
@@ -201,6 +203,8 @@ public void WriteObject(object value)
201203

202204
public void ReportTaskProgress(ITaskProgress taskProgress)
203205
=> Scheduler.BeginInvoke(() => TaskProgressList.Add(taskProgress));
206+
207+
204208
}
205209
}
206210
}

src/ResourceManager/Common/Commands.Common.Strategies/IAsyncCmdlet.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Collections.Generic;
16+
using System.Threading;
1617
using System.Threading.Tasks;
1718

1819
namespace Microsoft.Azure.Commands.Common.Strategies
@@ -54,5 +55,10 @@ public interface IAsyncCmdlet
5455
/// A `New` verb.
5556
/// </summary>
5657
string VerbsNew { get; }
58+
59+
/// <summary>
60+
/// Cancellation token for asynchonous operations.
61+
/// </summary>
62+
CancellationToken CancellationToken { get; }
5763
}
5864
}

src/ResourceManager/Compute/Commands.Compute/Manual/VirtualMachineScaleSetCreateOrUpdateMethod.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
267267

268268
var parameters = new Parameters(this, client);
269269

270-
var result = await client.RunAsync(
271-
client.SubscriptionId, parameters, asyncCmdlet, new CancellationToken());
270+
var result = await client.RunAsync(client.SubscriptionId, parameters, asyncCmdlet);
272271

273272
if (result != null)
274273
{

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ async Task StrategyExecuteCmdletAsync(IAsyncCmdlet asyncCmdlet)
423423
}
424424
}
425425

426-
var result = await client.RunAsync(
427-
client.SubscriptionId, parameters, asyncCmdlet, new CancellationToken());
426+
var result = await client.RunAsync(client.SubscriptionId, parameters, asyncCmdlet);
428427

429428
if (result != null)
430429
{

0 commit comments

Comments
 (0)