Answer the question
In order to leave comments, you need to log in
How to make async.js and express.js friends?
Help me figure it out
There is such a code, the point is that you first need to make a series of parallel requests and then display the callback on the screen in the browser. The code below doesn't work.
async.parallel([
function(){ ... },
function(){ ... }
],
function(){
app.get('/', function () {
res.send('test');
})
}
);
async.parallel([
function(){ ... },
function(){ ... }
],
function(){
}
);
app.get('/', function () {
res.send('test');
})
Answer the question
In order to leave comments, you need to log in
mayorovp - yes, logically, everything is right, I did it right away. But that didn't work either...
app.get('/', function (req, res) {
async.parallel([
function () {
...
},
function () {
...
},
],function () {
res.send('test');
});
})
Er... think again what you're doing. The first time you first execute your requests - and only then do you start listening for connections from the browser at all! Of course, you can't do anything.
The second time you wrote two parallel processes - one executes a bunch of requests, the second - listens to a request from the browser.
You must first receive a request from the browser - that is, app.get should be the first line. Then you need to make several requests - that is, there must be a call to async.parallel inside. And only at the very end should there be a call to res.send. I think now you yourself will be able to properly assemble this matryoshka.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question