Skip to content

Commit

Permalink
ADD:BRK: AsyncServiceSetupResult
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeago committed Dec 6, 2023
1 parent 0b50bf1 commit f25ed27
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Class `Louis.ComponentModel.ParsableStringConverter<T>` and method `Louis.ComponentModel.SimpleStringConverter.AddToTypeDescriptor<T>` offer a ready-made type converter for any type implementing [`IParsable<TSelf>`](https://learn.microsoft.com/en-us/dotnet/api/system.iparsable-1).
`ParsableStringConverter<T>` and `AddToTypeDescriptor<T>` are only available on target platforms where `IParsable<TSelf>` is available, i.e. .NET 7 and later versions.
- **BREAKING CHANGE:** In class `Louis.Threading.AsyncService`, virtual method `SetupAsync` now returns a `ValueTask<bool>` instead of a `ValueTask`. If the result of the task is `false`, the service is stopped and neither `ExecuteAsync` nor `TeardownAsync` are called.
- **BREAKING CHANGE:** In class `Louis.Threading.AsyncService`, the tasks returned from methods `WaitUntilStartedAsync` and `StartAndWaitAsync` now have a result of type `AsyncServiceSetupResult`, with the following meaning:
- `AsyncServiceSetupResult.Successful` means that `SetupAsync` completed with a `true` result;
- `AsyncServiceSetupResult.NotStarted` means that the service was stopped before being started and `SetupAsync` was therefore not called;
- `AsyncServiceSetupResult.Unsuccessful` means that `SetupAsync` completed with a `false` result;
- `AsyncServiceSetupResult.Canceled` means that `SetupAsync` was canceled;
- `AsyncServiceSetupResult.Faulted` means that `SetupAsync` threw an exception.

### Changes to existing features

Expand Down
7 changes: 3 additions & 4 deletions src/Louis.Hosting/AsyncHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ protected AsyncHostedService(ILogger logger)
async Task IHostedService.StartAsync(CancellationToken cancellationToken)
{
LogHostedServiceStarting();
if (await StartAndWaitAsync(cancellationToken).ConfigureAwait(false))
var setupResult = await StartAndWaitAsync(cancellationToken).ConfigureAwait(false);
if (setupResult == AsyncServiceSetupResult.Successful)
{
return;
}

// If AsyncService.StartAsync returns false, then either the service was canceled, or SetupAsync faulted.
cancellationToken.ThrowIfCancellationRequested();
ThrowHelper.ThrowInvalidOperationException("Service start faulted.");
ThrowHelper.ThrowInvalidOperationException($"Service start failed ({setupResult}).");
}

/// <inheritdoc/>
Expand Down
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/net462/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/net47/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/net6.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/net7.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.ComponentModel.ParsableStringConverter<T>
Louis.ComponentModel.ParsableStringConverter<T>.ParsableStringConverter() -> void
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
static Louis.ComponentModel.SimpleStringConverter.AddToTypeDescriptor<T>() -> void
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/net8.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.ComponentModel.ParsableStringConverter<T>
Louis.ComponentModel.ParsableStringConverter<T>.ParsableStringConverter() -> void
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
static Louis.ComponentModel.SimpleStringConverter.AddToTypeDescriptor<T>() -> void
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
10 changes: 9 additions & 1 deletion src/Louis/PublicAPI/netstandard2.1/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
*REMOVED*virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask
*REMOVED*Louis.Threading.AsyncService.StartAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.StopAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>!
*REMOVED*Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.StartAndWaitAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncService.StopAndWaitAsync() -> System.Threading.Tasks.Task<bool>!
Louis.Threading.AsyncService.WaitUntilStartedAsync() -> System.Threading.Tasks.Task<Louis.Threading.AsyncServiceSetupResult>!
Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Canceled = 3 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Faulted = 4 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.NotStarted = 1 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Successful = 0 -> Louis.Threading.AsyncServiceSetupResult
Louis.Threading.AsyncServiceSetupResult.Unsuccessful = 2 -> Louis.Threading.AsyncServiceSetupResult
virtual Louis.Threading.AsyncService.LogSetupCompleted(bool success) -> void
virtual Louis.Threading.AsyncService.SetupAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<bool>
Loading

0 comments on commit f25ed27

Please sign in to comment.