Skip to content

Compare async/await to ContinueWith #47075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Compare async/await to ContinueWith #47075

wants to merge 4 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 2, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

Hello,

As far as I understand, async/await is just syntactic sugar over the Task function ContinueWith. For instance, if we have a Task t and a function f, then X x = await t; return f(x); is the same as t.ContinueWith((x) => { return f(x.Result); });.

Then instead of comparing synchronous code versus async/await code, I would recommend to compare asynchronous code by ContinueWith to asynchronous code by async/await. In the particular breakfast example of this webpage, we would see 2 almost identical codes, because all async methods have only one or two awaits.

The async/await notation is called "monadic do-notation" in functional programming, and it is most useful when there are 3 or 4 monadic values to combine in a single function. Here that would mean 3 or 4 awaits in a single function, then we would see a big simplification compared to intertwined lambda functions inside ContinueWiths.

Moreover, the discussion of synchronous code might be skipped altogether in this page. The difference between monothread and multithread algorithms has become common these days, people are probably already familiar with them.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Fixes #21296.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/asynchronous-programming/index.md docs/csharp/asynchronous-programming/index

@BillWagner
Copy link
Member

Hi @copilot Can you start working on this again?

Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

Hi @copilot Can you start working on this again?

Sure! I'm resuming work on this issue. I'll be adding a comparison between ContinueWith and async/await approaches to show how async/await simplifies asynchronous code, especially when chaining multiple operations.

Copilot finished work on behalf of BillWagner July 3, 2025 14:01
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is good. I had a few comments to address before it's final.

@@ -0,0 +1,139 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this file because the snippets aren't included in the article.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the unused AsyncBreakfast-ContinueWith/Program.cs file in commit 3285a72.

… misleading text, use tag-based snippets

Co-authored-by: BillWagner <[email protected]>
@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 3, 2025
Copy link
Contributor Author

Copilot AI commented Jul 3, 2025

Overall, this is good. I had a few comments to address before it's final.

Addressed all the review comments in commit 3285a72.

@Copilot Copilot AI requested a review from BillWagner July 3, 2025 15:48
Copilot finished work on behalf of BillWagner July 3, 2025 15:48
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better. This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review July 3, 2025 15:49
@BillWagner BillWagner requested a review from a team as a code owner July 3, 2025 15:49
@BillWagner BillWagner requested a review from IEvangelist July 3, 2025 15:50
@BillWagner BillWagner enabled auto-merge (squash) July 3, 2025 15:50
@BillWagner BillWagner changed the title [WIP] Compare async/await to ContinueWith Compare async/await to ContinueWith Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async-task-programming/subsvc dotnet-csharp/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compare async/await to ContinueWith
2 participants