Skip to main content
106 votes

Are events only used for GUI programming?

Nope. They're really handy for implementing Observers and making sure that classes are closed to modification. Let's say we have a method that registers new users. public void Register(user) { ...
RubberDuck's user avatar
  • 8,971
70 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,171
53 votes

Are events only used for GUI programming?

Nope. A classic example of events being used in non-GUI logic are database triggers. Triggers are code that gets executed when a given event happen (INSERT,DELETE, etc). Seems like an event to me. ...
Tulains Córdova's user avatar
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,084
27 votes

Are events only used for GUI programming?

Event-based programming is actually also used for highly performant server programming. At a typical server workload, much of the time processing a result actually comes from I/O. For example, ...
ArTs's user avatar
  • 730
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
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
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
Accepted

Using asynchronous calls for heavy IO operation: How to prevent crushing the CPU?

While you may have 4 CPUs, you have only one hard-drive (unless you don't). The total performance will therefore be limited by your disk drive's read/write rate. Multiple threads isn't going to change ...
Nicol Bolas'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
  • 109k
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,171
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,509
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.5k
10 votes

Are events only used for GUI programming?

Events are also heavily used in network programming (e.g. Nginx) to avoid expensive busy-wait loops and instead provide a clean interface to know exactly when a certain operation is available(I/O, ...
edmz's user avatar
  • 201
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
  • 27.8k
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
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

What is the functional programming method for combining two "streams" of data?

This is where the monadic properties of Eithers come in handy (although you don't have to understand monads to take advantage of them). Most functional programming languages have a way to easily ...
Karl Bielefeldt's user avatar
7 votes

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

They do (well, most of them). The feature you're looking for is called threads. Threads have their own problems however: Because the code can be suspended at any point, you can't ever assume that ...
Stack Exchange Supports Israel'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

Does omitting await keyword once in the call stack break the asynchronous behavior of the whole stack?

In .net the async await keywords are an extension of the Task Parallel Library. When you do not await an async method it is almost equivalent to calling Task.Run(()=>A()) (There are some gotchas ...
RubberChickenLeader'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
5 votes

Are events only used for GUI programming?

Embedded systems are almost always inherently event-driven, even if they are not programmed explicitly as such. These events come from things like hardware interrupts, button presses, period analog-...
Radian's user avatar
  • 797
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

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