OneOf icon indicating copy to clipboard operation
OneOf copied to clipboard

Added overload to switch method for use with async code.

Open bwarthur opened this issue 3 years ago • 6 comments

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.

bwarthur avatar Feb 14 '22 15:02 bwarthur

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?

adnang avatar Apr 20 '22 10:04 adnang

Hi, would love to see this PR merged

fbouvard avatar Feb 14 '23 12:02 fbouvard

How does this compare to doing:

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

vflame avatar Jul 07 '23 19:07 vflame

I badly need this. Any chance this happens?

baynezy avatar Feb 02 '24 14:02 baynezy

Is this ever gonna merged?

md-redwan-hossain avatar Feb 29 '24 17:02 md-redwan-hossain

Sorry, I'm not keen on adding this, and increasing the code/assembly size. It seems to me that using the Match overload with the async keyword already handles this capability.

Perhaps you could release it as a standalone nuget package.

On Thu, 29 Feb 2024, 17:23 Md. Redwan Hossain, @.***> wrote:

Is this ever gonna merged?

— Reply to this email directly, view it on GitHub https://github.com/mcintyre321/OneOf/pull/106#issuecomment-1971612114, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDJ6TNCEDZ2427A7G5R2LYV5R25AVCNFSM5OLZ56QKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJXGE3DCMRRGE2A . You are receiving this because you were mentioned.Message ID: @.***>

mcintyre321 avatar Feb 29 '24 18:02 mcintyre321