Replies: 1 comment
-
Predictably, right after posting my question, I managed to sort it out! However, I'm going to leave the question here, as I still don't really understand it. I sorted out the warning by changing the code to this... await Jim()
.Match(async str => await DoStuff(str), ex => Task.Run(() => LogError(ex))); Now that both lambdas are async, the right overload is called. What I don't understand is why the compiler didn't use the Anyone able to explain? Thanks. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Probably doing something stupid here, but after a very helpful discussion about a similar question, I thought I had the hang of async lambdas. However, I've got another warning, and I don't understand why.
I have a two methods (implementation omitted for clarity)...
I'm using them like this...
Now, based on the explanation I had before, I would have expected that as
DoStuff
is anasync
method, the compiler would use theFunc<string, Task>
overload ofMatch
, and so be happy with the fact that the lambda I'm passing for the happy path is async.However, hovering my mouse over
Match
shows that it's using the overload that takes anAction<string>
, and Resharper gives me a warning "Avoid using 'async' lambdas when delegate return type is void."Can anyone explain why this is happening? What should I have done to make sure the right overload is called?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions