Because ContinueWith is considered antiquated in modern C# and shouldn't be used for a multitude of reasons? https://medium.com/@joni2nja/why-you-should-not-use-continue...
(I figured `ContinueWith` was just dumb naming to avoid 'map' at all costs, just like how Java went with `thenApply`.)
Have you heard the word of our lord and savior, LINQ?
In the article linked above: > ContinueWith allocates more than using async await
Does LINQ not carry a similar overhead?
Does LINQ's map come with a plethora of problems like I'm told Task's map does above?
Should you avoid mapping because 'it's the old callback model' which doesn't belong in modern code?
Is map fit for purpose, or has it been disavowed?
Or you can use it with Tasks. https://itnext.io/fun-csharp-doing-linq-to-tasks-because-tas...
(caution: contains the M word)
More from Microsoft: https://devblogs.microsoft.com/pfxteam/tasks-monads-and-linq... ; referencing Lippert https://ericlippert.com/category/monads/
ContinueWith is not a broken "map". What people usually want is Select. https://learn.microsoft.com/en-us/dotnet/csharp/linq/standar...
That's what you and I wrote. That's not what the article wrote.
"efforts to be async amount to nothing unless the entire call stack is async"
The entire call stack?
"it is best to go all in, and make everything async at once."
Go all in?
This beyond 'a little bit unclear' into 'incorrect' territory, especially since the preceding paragraph said "there's been lots of confusion on the best practices for async and how to use it properly."
Is there a single NB or asterisk-like comment on the whole page that walks back the "all in" comment to something like "calling sync from async is fine." ?
He makes no direct comment, afaik, on calling sync methods from async methods. The reader is left only with
efforts to be async amount to nothing unless the entire call stack is async
and it is best to go all in, and make everything async at once.
and must somehow parse this as some of the call stack, and make some things async.
> 1) Once you go async, all of your callers SHOULD be async, since efforts to be async amount to nothing unless the entire call stack is async.
> 2) In many cases, being partially asynchronous can be worse than being entirely synchronous.
> 3) Therefore it is best to go all in, and make everything async at once.
I agree that all callers should become async. But I disagree that all callees should also be async, which is what 2 and 3 seem to imply.
You don't async for async's sake; you async to route around delays caused by blocking calls.
In their good example,
they've included a line of business logic after the async machinery. If this logic grew to more than just (result + 1), I'd expect that code to be in a separate synchronous function.I probably also wouldn't write out DoSomethingAsync() in full, either in the simple example above, or in a version with more complicated result-handling. Most of it is boilerplate: start a function call one function un-async the result into one variable do one thing to that variable repack it as async return it
If you want 'one bigger than CallDependencyAsync()', why not:
and if the logic grows, then: