mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 10:12:50 +08:00
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".
This commit is contained in:
parent
fa15389158
commit
ca2e6ce0ad
@ -15,13 +15,10 @@ namespace Spectre.Console.Internal
|
|||||||
|
|
||||||
public T Run<T>(Func<T> func)
|
public T Run<T>(Func<T> func)
|
||||||
{
|
{
|
||||||
// Try aquiring the exclusivity semaphore
|
// Try acquiring the exclusivity semaphore
|
||||||
if (!_semaphore.Wait(0))
|
if (!_semaphore.Wait(0))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw CreateExclusivityException();
|
||||||
"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.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -36,12 +33,10 @@ namespace Spectre.Console.Internal
|
|||||||
|
|
||||||
public async Task<T> Run<T>(Func<Task<T>> func)
|
public async Task<T> Run<T>(Func<Task<T>> func)
|
||||||
{
|
{
|
||||||
// Try aquiring the exclusivity semaphore
|
// Try acquiring the exclusivity semaphore
|
||||||
if (!await _semaphore.WaitAsync(0).ConfigureAwait(false))
|
if (!await _semaphore.WaitAsync(0).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
// TODO: Need a better message here
|
throw CreateExclusivityException();
|
||||||
throw new InvalidOperationException(
|
|
||||||
"Could not aquire the interactive semaphore");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -53,5 +48,10 @@ namespace Spectre.Console.Internal
|
|||||||
_semaphore.Release(1);
|
_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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user