|
|
|
|
|
by mjpuser
2939 days ago
|
|
I agree that not having a natural flow of control is more prone programming debugging. However, he does say things that are wrong, ex:
"It's impossible to slow down the pace of accepting new incoming client connections."
You can slow down the pace by doing the following: const http = require('http');
let count = 0;
const THRESHOLD = 1;
const server = http.createServer((req, res) => {
if (count++ < THRESHOLD) {
// do work
res.write('success');
res.end();
setTimeout(() => count--, 10 * 1000);
} else {
res.write('limit');
res.end();
count--;
}
});
server.listen(10000);
|
|
Second, your solution does not limit the acceptance of new incoming client connections, it only limits the frequency with which "work" is done. That solves some possible problems, true, but it does not solve the problem that the post is about.
On the other hand, I see no evidence in this blog post that callbacks are the inherent cause of the flow-control problem; it's rather that high-level languages that abstract the connection event are the inherent cause. Callbacks or no callbacks, the problem is the level of abstraction.