Replies: 7 comments
-
The most crucial information in your question is missing, what do For example: Unit Foo() => unit;
Task<Unit> Bar() => unit.AsTask();
TryAsync(unit).Match(Succ: _ => Foo(), Fail: _ => Bar()); Also, avoid using The second Warnings comes from the fact that non- Another thing I like to do is defining an extension method |
Beta Was this translation helpful? Give feedback.
-
@CK-LinoPro Thanks for the explanation. My problem was that Thanks also for the explanation about the pure warning. Makes a lot of sense. I like the extension method, as you say, makes it clearer. |
Beta Was this translation helpful? Give feedback.
-
Just in case you haven't seen it, there is |
Beta Was this translation helpful? Give feedback.
-
@StanJav Ooh, I didn't realise it was part of the library (obvious really, it's too useful to have been missed!). Thanks for pointing that out. |
Beta Was this translation helpful? Give feedback.
-
@StanJav Hmm, just tried it, and it can't resolve the symbol I'm trying this on the end of a call to Any ideas? |
Beta Was this translation helpful? Give feedback.
-
Duh, silly me. I was looking for it as an extension method, not a standalone method (I know, I should read people's replies more carefully!). Thanks again. |
Beta Was this translation helpful? Give feedback.
-
@CK-LinoPro and @StanJav I have come across a similar issue, which I explained in a new discussion (as it's not quite the same as this one). Would you be able to take a look and see what I did wrong? Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Suppose I have code like this...
...where
DoSomething
returns aTryAsync
andOnSuccess
is synchronous.Resharper gives me the warning shown in the title on the
async
keyword in the failure lambda. As far as I know, that warning means that if anything throws an exception in the asyncOnFailure
method, the exception won't be caught, as it will be in the returnedTask
that isn't handled, as the compiler is assuming the failure lambda is void.My guess (and please correct me if I'm wrong) is that as
DoSomething
is a sync void method, the compiler uses the overload forMatch
that takes anAction
for the success lambda, as opposed to the overload that takes aFunc
.I know I could change the code to...
...but this seems odd. It also gives a warning "Return value of pure method is not used" on the call to
Match
, but I guess I can live with that, as I know the return value isn't significant.Anyone able to advise what is the best way to do this? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions