Skip to content

Conversation

@bwarthur
Copy link

Fixes #84.

I went with doing an overload of Switch instead of a separate SwitchAsync because I think it will provide a better default experience. As soon as someone adds async to each of the actions, it will switch over to the Func<> overload instead of relying on someone to know to go look for an explicitly named Async version.

@adnang
Copy link

adnang commented Apr 20, 2022

Will this result in IDE's highlighting that the Switch method is now async, and requires an await?

The problem i tried to highlight in the original issue wasn't with dicovery of the async method, but rather its usage - IMO, developers will still forget to call await on the method if its not explicit when there's a non-async overload.

Having an async overload without the Async suffix is quite unusual for stable .NET libraries, I think it will cause more confusion when the return type has changed to a Task without the method name changing.

This SO post has a similar belief https://stackoverflow.com/a/47810905

@mcintyre321 what do you think?

}}
#if !NET35
public Task Switch({RangeJoined(", ", e => $"Func<T{e}, Task> f{e}")})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to SwitchAsync.

throw new InvalidOperationException();
}}
#if !NET35
Copy link

@ChristopherHaws ChristopherHaws Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be (!NETFRAMEWORK || NET40_OR_GREATER) instead of !NET35

@fbouvard
Copy link

Hi, would love to see this PR merged

@vflame
Copy link

vflame commented Jul 7, 2023

How does this compare to doing:

await oneOf.Match<Task>( t1 => Task.CompletedTask, t2 => Task.CompletedTask);

@fbouvard fbouvard mentioned this pull request Jan 23, 2024
@baynezy
Copy link

baynezy commented Feb 2, 2024

I badly need this. Any chance this happens?

@md-redwan-hossain
Copy link

Is this ever gonna merged?

@mcintyre321
Copy link
Owner

mcintyre321 commented Feb 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a .SwitchAsync method which behaves as .Match returning a Task

9 participants