113
votes
Accepted
Is there really a fundamental difference between callbacks and Promises?
It is fair to say promises are just syntactic sugar. Everything you can do with promises you can do with callbacks. In fact, most promise implementations provide ways of converting between the two ...
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) {
...
67
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 ...
64
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 ...
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.
...
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, ...
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 ...
22
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 ...
19
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 ...
18
votes
Does Akka obsolesce JMS/AMQP message brokers?
Actor Model
The actor model is computer science strategy for building applications that handle lots of concurrent computation and stateful processing. It's not the only strategy but it's a very well ...
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 - ...
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 ...
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 ...
13
votes
Accepted
"Reactive programming is programming with asynchronous data streams." is this true?
The most common example of Reactive programming that I've heard about is a spreadsheet program that has computed values.
Personally, I would think about a spreadsheet more as a hybrid between ...
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,...
13
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....
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 ...
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, ...
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 ...
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. ...
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 ...
7
votes
Accepted
Trying to understand some async/await behavior
When you call it like this:
await GetChecksum(1,@"E:\Files\ISO\5gbfile.iso");
await GetChecksum(2,@"E:\Files\ISO\4gbfile.iso");
await GetChecksum(3,@"E:\Files\ISO\3gbfile.iso");
await GetChecksum(4,@"...
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 ...
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 ...
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 ...
6
votes
Accepted
Do any languages have syntax for promises?
Yes, there are several such languages:
C# has async methods and the await keyword. Technically speaking, any object which implements a certain syntactic pattern can be awaited, but the intention is ...
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 ...
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 ...
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 ...
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-...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
asynchronous-programming × 175async × 36
c# × 32
javascript × 21
multithreading × 20
.net × 14
c++ × 13
event-programming × 12
architecture × 11
design-patterns × 10
microservices × 10
java × 9
node.js × 9
concurrency × 8
design × 7
message-queue × 7
synchronization × 6
python × 5
programming-languages × 5
c × 5
callbacks × 5
terminology × 4
web-services × 4
architectural-patterns × 4
io × 4