4 ms·
> why not Because ContinueWith is considered antiquated in modern C# and shouldn't be used for a multitude of reasons? https://medium.com/@joni2nja/why-you-sho
by Hawxy 2y ago
> why not
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-continuewith-in-your-async-code-c9eaf6087e64 https://medium.com/@joni2nja/why-you-should-not-use-continue...
- mrkeen 2y agoSo does C# not have map yet? (I figured `ContinueWith` was just dumb naming to avoid 'map' at all costs, just like how Java went with `thenApply`.)
- Hawxy 2y agoSure, you can use it like that, but it's not considered good practice. I think the context missing here is that most modern C# applications are going to be async all of the way down. The entry point can be async. Background service abstractions are async. Your API endpoints in ASP.NET Core are typically async as you're going to be calling some async I/O anyways (database queries, HTTP clients). There's no benefit to writing something in the old callback model when the rest of your code is async/await anyways.
- pjc50 2y ago> So does C# not have map yet? Have you heard the word of our lord and savior, LINQ?
- mrkeen 2y agoOf course. In the article linked above: > ContinueWith allocates more than using async await Does LINQ not carry a similar overhead?
- pjc50 2y agoYou said, "So does C# not have map yet?", knowing full well that it did, and are now moving the goalposts.
- mrkeen 2y agoI'll rephrase. 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?
- pjc50 2y agoMapping (spelt "Select" quite often in LINQ) is entirely normal and promoted going forwards. It can optimize extremely well for simple cases. By default it is not parallel and compiles to an underlying for loop. Or you can use it with Tasks. https://itnext.io/fun-csharp-doing-linq-to-tasks-because-task-is-a-monad-2fd87a310a03 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/ https://devblogs.microsoft.com/pfxteam/tasks-monads-and-linq... ; referencing Lippert https://ericlippert.com/category/monads/ 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/standard-query-operators/projection-operations https://learn.microsoft.com/en-us/dotnet/csharp/linq/standar...