OneOf
OneOf copied to clipboard
Added overload to switch method for use with async code.
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.
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?
Hi, would love to see this PR merged
How does this compare to doing:
await oneOf.Match<Task>( t1 => Task.CompletedTask, t2 => Task.CompletedTask);
I badly need this. Any chance this happens?
Is this ever gonna merged?
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: @.***>