I've seen too many times developers using .Switch instead of .Match when calling async void code inside the lambdas, because the default behaviour when you want to perform a void operation is to .Switch rather than .Match, resulting in
OneOf<T1, T2> res = GetResult();
res.Switch(async t1 => await ProcessT1(t1), async t2 => await ProcessT2(t2));
which isn't awaited correctly (resulting in exceptions being lost)
A .SwitchAsync method which accepts a Func<T, Task> for each parameter would make it really clear than an async option can be used (even gives an IDE hint), and the behaviour would be the same as .Match(Func<T, Task>)
I've seen too many times developers using
.Switchinstead of.Matchwhen calling async void code inside the lambdas, because the default behaviour when you want to perform a void operation is to.Switchrather than.Match, resulting inwhich isn't awaited correctly (resulting in exceptions being lost)
A
.SwitchAsyncmethod which accepts aFunc<T, Task>for each parameter would make it really clear than an async option can be used (even gives an IDE hint), and the behaviour would be the same as .Match(Func<T, Task>)