Skip to content

Compare async/await to ContinueWith #21296

Closed
@VincentSe

Description

@VincentSe

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.

Metadata

Metadata

Labels

async-task-programming/subsvcdotnet-csharp/svcin-prThis issue will be closed (fixed) by an active pull request.okr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions