Skip to main content
69 votes
Accepted

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility? Without explicit points where a ...
amon's user avatar
  • 135k
68 votes
Accepted

Who did async/await first?

Haskell (2012) There is an async package for Haskell (2012) by Simon Marlow. In case you don't know, Simon Marlow is a lead developer of Haskell. Notes: Simon Marlow joined Microsoft research in 1998 ...
Theraot's user avatar
  • 9,201
50 votes
Accepted

Purpose of async/await in web servers

As far as I can tell, every request is already being run on a thread pool (as empirically tested by logging the thread ID during each request), so making all calls use async/await within your ...
Ccm's user avatar
  • 2,144
27 votes

Why don't programming languages automatically manage the synchronous/asynchronous problem?

What you are missing, is the purpose of async operations: They allow you to make use of your waiting time! If you turn an async operation, like requesting some resource from a server, into a ...
cmaster - reinstate monica's user avatar
24 votes
Accepted

Expensive constructors. Should they exist? Should they be replaced?

Don't put i/o in constructor. It leads to so much trouble, e.g. how will you test that? There are some valid cases for such thing in other languages (e.g. RAII in C++ and Rust) but I don't think it ...
freakish's user avatar
  • 2,604
23 votes
Accepted

Is the C# async/Task construct equivalent to Java's Executor/Future?

C#'s Task is somewhere halfway between Java's Future and CompletableFuture. The Result property is equivalent to calling get(), ContinueWith() does the things the massive array of continuation ...
Sebastian Redl's user avatar
21 votes

Expensive constructors. Should they exist? Should they be replaced?

This is very similar to an ancient StackOverflow question. I suggest reading my answer there, as it hasn't changed. Arguing that the constructor must not be slow is a mindset that comes from real-time ...
Oddthinking's user avatar
  • 1,988
20 votes

Calling multiple async services in parallel

One issue I see using Task.WhenAll is that it does not return results But it does return the results. They'll all be in an array of a common type, so it's not always useful to use the results in ...
Servy's user avatar
  • 1,986
18 votes

Why is there a shift towards asynchronous and event driven programming?

The "async" approach better facilitates human reasoning. When most people drive, they don't need to concern themselves with how every element of the car is interacting. Forget the tires - ...
TheRubberDuck's user avatar
14 votes

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Some do. They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a ...
Telastyn's user avatar
  • 110k
14 votes

Why is it necessary for every new api to be async?

I feel that c# has become a very wordy language and I'm not happy to have to code in the async style like this. Oh, but that is not wordy at all. You are not writting something like this: client....
Theraot's user avatar
  • 9,201
13 votes

Why don't programming languages automatically manage the synchronous/asynchronous problem?

There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features. As long as you have some way of expressing asynchrony,...
Jörg W Mittag's user avatar
12 votes

API Gateway (REST) + Event-Driven Microservices

Repeat after me: REST and asynchronous events are not alternatives. They're completely orthogonal. You can have one, or the other, or both, or neither. They're entirely different tools for ...
Jack's user avatar
  • 4,529
12 votes

Purpose of async/await in web servers

A threadpool does not have infinite threads. Each time you synchronously wait, you are holding onto a thread and doing nothing with it. If you instead await, the suspension will bubble up to the ...
Caleth's user avatar
  • 11.6k
10 votes

How can message queues improve scalability?

It's not that queues are more scalable, its the fact that two services communicating through queue means the communication is asynchronous. Asynchronous communication is far more scalable than ...
Matan Shabtay's user avatar
10 votes

Why is there a shift towards asynchronous and event driven programming?

Fundamentally the answer comes down to the fact that threads are not free. There is overhead associated with each thread. I found this article which is written by former Intel Engineer Arch D. ...
JimmyJames's user avatar
  • 28.9k
9 votes

Purpose of async/await in web servers

It sounds to me like there are 2 wrong assumptions here. The point of async/await isn't to free up the socket/connection. You're freeing up the thread to do other work during some async operation. ...
Mars's user avatar
  • 273
8 votes

Why is there a shift towards asynchronous and event driven programming?

A lot of event driven programming is because the applications are event driven. You're running code to handle a button click, or a received packet, or a timer expiring. That sort of code is actually ...
Karl Bielefeldt's user avatar
8 votes

Not await an asynchronous method because it is like an endless loop - good practice?

I think you are awaiting the result somewhere: in StopValueReading. Except rather than doing so through the Task you have to define your own semaphore to keep track of it. You could eliminate ...
pjc50's user avatar
  • 14.8k
7 votes

async+await == sync?

I stumbled on this with the same question in mind, yet after reading the responses the question seems to linger, confused by references to "magic under the hood". From the above-mentioned ...
oversynched's user avatar
7 votes
Accepted

In Java's Fork/Join is the operation for combining results limited to addition?

join does not combine any results. It simply awaits and retrieves the result of the single task you call it on. Any combining of results from multiple tasks happens in code you write after the join ...
Sebastian Redl's user avatar
6 votes
Accepted

Is there a pattern for a chain of asynchronous calls, followed by a cleanup?

You can use a promise chain like the idiomatic q one, roughly: doSomethingThatReturnsAPromise .then(function (result, error) { if (error) { [the previous command failed in ...
l0b0's user avatar
  • 11.5k
6 votes

What happens in terms of call stacks when 10000 setTimeouts are called?

For your custom programming language, the answer is "whatever you want it to be". Once you've defined your execution model, that will tell you what your call stacks look like. In particular ...
Philip Kendall's user avatar
6 votes

How is async implemented natively?

Well, "async" is an umbrella term and different pieces of async, over different runtimes are implemented in different ways. For network i/o typically such runtime would take advantage of ...
freakish's user avatar
  • 2,604
5 votes

Why do many languages semantically distinguish "async" functions from "non-async" ones?

I think you're reading too much into this. async changes the return type of a function. I don't know how or if C# denotes that beyond the async, but in Scala (and I believe Kotlin but I'm not as ...
Karl Bielefeldt's user avatar
5 votes

Why do many languages semantically distinguish "async" functions from "non-async" ones?

The reason you need to mark methods as async in C# in order to use await as a keyword inside of them is that C# was already a well-established language by the time this was added as a new feature, and ...
Mason Wheeler's user avatar
5 votes
Accepted

Correct usage of async/await and Task.Run()

At first glance, I would say the async/await code looks OK. However, there are a few things to consider. Don't change global or class state in a task. Have the task be a true function (i.e. does ...
Berin Loritsch's user avatar
5 votes
Accepted

Design for avoiding concurrent calls to an interface implementation

First, I would create a decorator / wrapper that synchronizes calls, instead of putting it into implementation. And I would implement it using queue instead of using a lock. TaskQueue from this other ...
Euphoric's user avatar
  • 37.8k
5 votes
Accepted

Is it okay for async function to update a common object

Having each async method update a common object risks running into threading/non-deterministic order issues with the results. So rather than have each async method update a common object, have each ...
David Arno's user avatar
  • 39.5k

Only top scored, non community-wiki answers of a minimum length are eligible