-
-
Notifications
You must be signed in to change notification settings - Fork 186
Open
Description
I couldn't find this in the issues or documentation: Is it allowed to switch on SmartEnum values using the .When().Then() pattern, when the Then() action delegate is asynchronous?
For example, in a FastEndpoints endpoint I currently have the following:
public override Task HandleAsync(
ListAddressRequest request,
CancellationToken cancellationToken)
{
ThrowArgumentNullException.If.Null(request);
var country = Country.FromValue(request.Address.Country);
country
.When(Country.Belgium).Then(async () =>
{
var listResult = await this.ListBelgiumAddressesAsync(request, cancellationToken);
await this.SendResultAsync(listResult);
})
.Default(async () =>
{
var errorResult = Result.Error(new ErrorList
(
ErrorMessages: [$"Country '{country.Value}' is not supported."]
));
await this.SendResultAsync(errorResult);
});
return Task.CompletedTask;
}(Country is SmartEnum<Country, string> where each value is the country code.)
Both action delegates passed to Then() and Default() are async, and the code compiles. But will this execute correctly?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels