Chaining async methods. Method not found
I want to have something like this
but this gives me an error
Cannot resolve symbol 'VerifyUser'
it's because CreateUser
returns Task<T>
if I write like this
or like this
then it works as expected
but second and third solution it's ugly.
How to achieve desired syntax?15 Replies
its similiar problem to this
https://stackoverflow.com/questions/25302178/using-async-tasks-with-the-builder-pattern
but having
Then
it's not a solution for me 😦The second solution is preferable
not for me, it’s ugly. If I have 10 more methods that I can chain then I will assign foo multiple times just to call next method
The third solution, then
Every
async
method needs to be await
ed to get the actual data from it that isn't wrapped in a Task
Period
However you want to chain it is up to you, but chain it you must
Because Task<Foo>
will not have the methods of Foo
yes I understand, but there has to be workaround. You wrote yourself that he has no methods for it. So I can write extension method for Task<Foo> 😉
That method would still have to
await
inside
And thus, would need to be async
And thus, would need to be awaited itselfyes, but caller would does not see it
and it would be as first example
Yes the caller would see
Or... huh
Not sure tbh
I was never into going against the grain of the languages I use, so no idea tbh
Try if, if writing 2783645 additional largely useless methods would fulfill your aesthetic needs lmao
lol, so you defending your lack of knowledge with some bullshit that I am doing something against language 😄
next time if you don’t know something. Don’t respond, as you are clearly not capable of helping if it’s beyond your skill level
Probably you didn’t even used templates if you are writing nonsense about writing millions of methods.
Sad 😞
No, I'm defending the use of a simple additional variable instead of writing at least 4 lines of an extension method
instead of
One requires an additional variable — the horror!
The other requires a whole another class and a method
Assuming it works
It's not beyond my skill level, far from it, I just try to not thing of how to write the most useless and verbose code possible
- in your example
a
and b
have different types, in my example the have the same type
- what if you have 10 other methods? Then you are going to have 10 other variables? Is it still readable and nice? Can it be solve with one method? (I think it can)
even if that would mean to create 10-20 extra variables that have no purpose? oh, interesting
so creating N extra variables is not vervose and useless code, but one extra method for chaining is? 😄Eh, go ahead with your plan then
ah, so when we expand example to be more difficult that does not fit your point, then you no longer have answer, so only you can say "whatever" and leave.
Yeah, nah, I simply don't care enough to continue arguing
for me it looks like you are not good with helping. If anyone challenges your advice (because in this case it's opinion, and not a real argument) then you are "offended" and leave what ever it is
btw check Language.Ext nuget package, maybe that will help you a bit widen your horizons
for anyone that would be interested I've endup with something like this
it's not ideal, but it's ok