inside a get request fucntion to mysql db and After two awaits on promises to get two lists (tab1 and tab2) filled, i want to get the intersection between them. tab1 and tab2 are lists of strings.
const app = express();
var intersectionBetween = function(a1,a2){
return a1.filter(function(n) { return a2.indexOf(n) !== -1;});
};
app.get('/getPackages', async (req, res) => {
var tab1= []
var tab2= []
const promiseIntersection = (a1, a2) => {
return new Promise((res, rej)=> {
intersectionBetween(a1, a2, function (err, resultsss){
if (err) rej(err);
return res(resultsss)
});
})
}
const intersectionb = await promiseIntersection(tab1, tab2);
console.log("efe",intersectionb)
res.send('Posts fetched...');
});
app.listen(3000, () => console.log("Express server is runnig at port: 3000"))
I wanted to get the intersection but when I go in the browser under '/getPackages' the browser runs forever without returning anything. Can anyone help?
After two awaits on promises to get two lists (tab1 and tab2) filled, you can directly call it and get intersection. There is nothing async.
app.get('/getPackages', async (req, res) => {
var tab1= []
var tab2= []
const intersectionb = intersectionBetween(tab1, tab2);
console.log("efe",intersectionb)
res.send('Posts fetched...');
});