From ca2e6ce0add89a22055024953c86b002296c81fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Sun, 3 Oct 2021 18:47:22 +0200 Subject: [PATCH] Improve the error message when acquiring the interactive semaphore fails Using the same error message as in the sync version of the `Run` method which is indeed much better than "Could not aquire the interactive semaphore". --- .../Internal/DefaultExclusivityMode.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Spectre.Console/Internal/DefaultExclusivityMode.cs b/src/Spectre.Console/Internal/DefaultExclusivityMode.cs index 4a52039..1c675e9 100644 --- a/src/Spectre.Console/Internal/DefaultExclusivityMode.cs +++ b/src/Spectre.Console/Internal/DefaultExclusivityMode.cs @@ -15,13 +15,10 @@ namespace Spectre.Console.Internal public T Run(Func func) { - // Try aquiring the exclusivity semaphore + // Try acquiring the exclusivity semaphore if (!_semaphore.Wait(0)) { - throw new InvalidOperationException( - "Trying to run one or more interactive functions concurrently. " + - "Operations with dynamic displays (e.g. a prompt and a progress display) " + - "cannot be running at the same time."); + throw CreateExclusivityException(); } try @@ -36,12 +33,10 @@ namespace Spectre.Console.Internal public async Task Run(Func> func) { - // Try aquiring the exclusivity semaphore + // Try acquiring the exclusivity semaphore if (!await _semaphore.WaitAsync(0).ConfigureAwait(false)) { - // TODO: Need a better message here - throw new InvalidOperationException( - "Could not aquire the interactive semaphore"); + throw CreateExclusivityException(); } try @@ -53,5 +48,10 @@ namespace Spectre.Console.Internal _semaphore.Release(1); } } + + private static Exception CreateExclusivityException() => new InvalidOperationException( + "Trying to run one or more interactive functions concurrently. " + + "Operations with dynamic displays (e.g. a prompt and a progress display) " + + "cannot be running at the same time."); } }