Skip to content

Commit ea371d6

Browse files
committed
fix async task running issue in spinner
1 parent 5fa6916 commit ea371d6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/ConsoleR/ConsoleR.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1414
</PropertyGroup>
1515
<PropertyGroup>
16-
<Version>0.3.3</Version>
16+
<Version>0.3.4</Version>
1717
<PackageId>Doroudi.ConsoleR</PackageId>
1818
<Authors>Saeid Doroudi</Authors>
1919
<Description>ConsoleR is set of utilities to make awesome console apps in .Net</Description>

src/ConsoleR/Spinner/Spinner.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ private void Spin()
2525
}
2626

2727
public async Task Start(Action action, string message = "")
28+
{
29+
await Start(() => Task.Run(action), message);
30+
}
31+
32+
public async Task Start(Func<Task> asyncAction, string message = "")
2833
{
2934
_message = message;
3035
System.Console.CursorVisible = false;
@@ -39,12 +44,13 @@ public async Task Start(Action action, string message = "")
3944

4045
try
4146
{
42-
action.Invoke();
47+
// Await the async action
48+
await asyncAction.Invoke().ConfigureAwait(false);
4349
Stop(_message);
4450
}
4551
catch (Exception ex)
4652
{
47-
Stop(errorMessage:ex.Message);
53+
Stop(errorMessage: ex.Message);
4854
}
4955
finally
5056
{

0 commit comments

Comments
 (0)