diff --git a/src/Spectre.Console/Widgets/Progress/Progress.cs b/src/Spectre.Console/Widgets/Progress/Progress.cs index 0e34b6d..80761fe 100644 --- a/src/Spectre.Console/Widgets/Progress/Progress.cs +++ b/src/Spectre.Console/Widgets/Progress/Progress.cs @@ -68,6 +68,18 @@ namespace Spectre.Console task.GetAwaiter().GetResult(); } + /// + /// Starts the progress task list and returns a result. + /// + /// The result type. + /// he action to execute. + /// The result. + public T Start(Func func) + { + var task = StartAsync(ctx => Task.FromResult(func(ctx))); + return task.GetAwaiter().GetResult(); + } + /// /// Starts the progress task list. /// @@ -82,13 +94,13 @@ namespace Spectre.Console _ = await StartAsync(async progressContext => { - await action(progressContext); + await action(progressContext).ConfigureAwait(false); return default; - }); + }).ConfigureAwait(false); } /// - /// Starts the progress task list. + /// Starts the progress task list and returns a result. /// /// The action to execute. /// The result type of task. diff --git a/src/Spectre.Console/Widgets/Progress/Status.cs b/src/Spectre.Console/Widgets/Progress/Status.cs index 94634fb..d11fe4a 100644 --- a/src/Spectre.Console/Widgets/Progress/Status.cs +++ b/src/Spectre.Console/Widgets/Progress/Status.cs @@ -52,6 +52,19 @@ namespace Spectre.Console task.GetAwaiter().GetResult(); } + /// + /// Starts a new status display. + /// + /// The result type. + /// The status to display. + /// he action to execute. + /// The result. + public T Start(string status, Func func) + { + var task = StartAsync(status, ctx => Task.FromResult(func(ctx))); + return task.GetAwaiter().GetResult(); + } + /// /// Starts a new status display. /// @@ -67,23 +80,23 @@ namespace Spectre.Console _ = await StartAsync(status, async statusContext => { - await action(statusContext); + await action(statusContext).ConfigureAwait(false); return default; - }); + }).ConfigureAwait(false); } /// - /// Starts a new status display. + /// Starts a new status display and returns a result. /// - /// The status to display. - /// he action to execute. /// The result type of task. + /// The status to display. + /// he action to execute. /// A representing the asynchronous operation. - public async Task StartAsync(string status, Func> action) + public async Task StartAsync(string status, Func> func) { - if (action is null) + if (func is null) { - throw new ArgumentNullException(nameof(action)); + throw new ArgumentNullException(nameof(func)); } // Set the progress columns @@ -108,7 +121,7 @@ namespace Spectre.Console return await progress.StartAsync(async ctx => { var statusContext = new StatusContext(ctx, ctx.AddTask(status), spinnerColumn); - return await action(statusContext).ConfigureAwait(false); + return await func(statusContext).ConfigureAwait(false); }).ConfigureAwait(false); } }