Closed
Description
🚀 Feature Proposal
It could be super to have each loops (for example eachCell or in my case eachRow) as an asynchronous funtion...
Motivation
I'm using KoaJs working with Promises and I try to make a script where everyRow should do a query to database ... But it do the job after I needed it ... Because eachRow is not an async function ...
Example
For example I did :
let products = [];
worksheet.eachRow((row, rowNumber) => {
if(rowNumber != 1) {
let id = row.getCell('A');
if(id) {
let datas = await ProductManager.get(id);
products.push(datas);
}
else {
products.push({
label: row.getCell('B'),
price: row.getCell('C'),
});
}
}
}
return ProductManager.save(products);
But as I said it's not waiting the DB call to do the save function ...
So for the moment I did a second loop like that :
let products = [];
worksheet.eachRow((row, rowNumber) => {
if(rowNumber != 1) {
products.push({
id : row.getCell('A'),
label : row.getCell('B'),
price : row.getCell('C'),
});
}
});
for(let i = 0, length = products.length; i < length; i++) {
if(products[i].id) {
let datas = await ProductManager.get(products[i].id);
products[i] = datas;
}
else {
products[i] = {
label: products[i].label,
price: products[i].price,
};
}
}
return ProductManager.save(products);
So it would be great if we could have a asyncEachRow like this :
await worksheet.asyncEachRow(async (row, rowNumber) => {
Metadata
Metadata
Assignees
Labels
No labels