Skip to content

Commit 71902db

Browse files
committed
async void if we're not going to actually await it
1 parent 6674e46 commit 71902db

4 files changed

Lines changed: 6 additions & 10 deletions

File tree

GrasshopperAsyncComponent/GH_AsyncComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ protected override void SolveInstance(IGH_DataAccess da)
188188
// Let the worker collect data.
189189
currentWorker.GetData(da, Params);
190190

191-
var currentRun = new Task<Task>(
191+
var currentRun = new Task(
192192
async () =>
193193
{
194194
await currentWorker.DoWork(_reportProgress, Done).ConfigureAwait(true);

GrasshopperAsyncComponent/WorkerInstance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class WorkerInstance<T>(T parent, string id, CancellationToken c
3030
/// <b>Make sure you always check as frequently as you can if <see cref="WorkerInstance{T}.CancellationToken"/> is cancelled. For an example, see the PrimeCalculatorWorker example.</b>
3131
/// </summary>
3232
/// <param name="reportProgress">Call this to report progress up to the parent component.</param>
33-
public abstract Task DoWork(Action<string, double> reportProgress, Action done);
33+
public abstract void DoWork(Action<string, double> reportProgress, Action done);
3434

3535
/// <summary>
3636
/// Write your data setting logic here. <b>Do not call this function directly from this class. It will be invoked by the parent <see cref="GH_AsyncComponent{T}"/> after you've called `Done` in the <see cref="DoWork"/> function.</b>

GrasshopperAsyncComponentDemo/SampleImplementations/Sample_PrimeCalculatorAsyncComponent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public PrimeCalculatorWorker(
5858
)
5959
: base(parent, id, cancellationToken) { }
6060

61-
public override Task DoWork(Action<string, double> reportProgress, Action done)
61+
public override void DoWork(Action<string, double> reportProgress, Action done)
6262
{
6363
try
6464
{
@@ -70,11 +70,9 @@ public override Task DoWork(Action<string, double> reportProgress, Action done)
7070
//No need to call `done()` - GrasshopperAsyncComponent assumes immediate cancel,
7171
//thus it has already performed clean-up actions that would normally be done on `done()`
7272
}
73-
74-
return Task.CompletedTask;
7573
}
7674

77-
public void CalculatePrimes(Action<string, double> reportProgress)
75+
private void CalculatePrimes(Action<string, double> reportProgress)
7876
{
7977
// 👉 Checking for cancellation!
8078
CancellationToken.ThrowIfCancellationRequested();

GrasshopperAsyncComponentDemo/SampleImplementations/Sample_UslessCyclesComponent.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private sealed class UselessCyclesWorker(
2626
{
2727
private int MaxIterations { get; set; } = 100;
2828

29-
public override Task DoWork(Action<string, double> reportProgress, Action done)
29+
public override void DoWork(Action<string, double> reportProgress, Action done)
3030
{
3131
try
3232
{
@@ -38,11 +38,9 @@ public override Task DoWork(Action<string, double> reportProgress, Action done)
3838
//No need to call `done()` - GrasshopperAsyncComponent assumes immediate cancel,
3939
//thus it has already performed clean-up actions that would normally be done on `done()`
4040
}
41-
42-
return Task.CompletedTask;
4341
}
4442

45-
public void RunUselessCycles(Action<string, double> reportProgress)
43+
private void RunUselessCycles(Action<string, double> reportProgress)
4644
{
4745
// Checking for cancellation
4846
CancellationToken.ThrowIfCancellationRequested();

0 commit comments

Comments
 (0)