HELP !!
các bạn xử lý hộ mình cái promise này để lấy đồng thời kq1 và kq2 (không dùng then lồng nhau)
var kq1='';
var kq2='';
var promise = new Promise(function(resolve, reject){
var kq2='';
var promise = new Promise(function(resolve, reject){
req.connect.query(`select xxx from JAV1 `
).then(function(rows){
kq1=rows;
})
).then(function(rows){
kq1=rows;
})
req.connect.query(`select yyy from JAV2 `
).then(function(rows){
kq2=rows;
})
).then(function(rows){
kq2=rows;
})
resolve(kq1,kq2);
});
promise.then(
function(xx,yy){
});
promise.then(
function(xx,yy){
console.log('kq1=='+xx) // Fuck đéo thấy gì
console.log('kq2=='+yy) // Fuck đéo thấy gì
console.log('kq2=='+yy) // Fuck đéo thấy gì
}
);
);
Resolve: Promise.all hoặc Promise.props
Promise.all([
req.connect.query('select xxx from JAV1'),
req.connect.query('select yyy from JAV2')
])
.then((response) => {
// if query 1 or query 2 has no data, the response always has 2 elements. Same with input
var kq1 = response[0]
var kq2 = response[1]
})
req.connect.query('select xxx from JAV1'),
req.connect.query('select yyy from JAV2')
])
.then((response) => {
// if query 1 or query 2 has no data, the response always has 2 elements. Same with input
var kq1 = response[0]
var kq2 = response[1]
})
let jav1 = req.connect.query(...);
let jav2 = ...;
Promise.all(jav1, jav2).then(([xx, yy]) => {
.....
});
Chú ý dấu [ ] array.
let jav2 = ...;
Promise.all(jav1, jav2).then(([xx, yy]) => {
.....
});
Chú ý dấu [ ] array.