Вот решение этой проблемы. Я добавил метод ожидания, который возвращает Promise.
while((batchOffset + batchSize) <= products.length) {
const entries = [];
const productsBatch = products.slice(batchOffset, (batchOffset+batchSize));
// Wait between API calls to avoid hitting Google API quota limits
await this.wait(100);
// Send a batch of n products to Google content API
contentApi.products.custombatch(
{
requestBody: {
entries: entries,
},
},
(err, res) => {
// handle err and response
if (err !== null || res.status !== 200) {
this.logger.log(
'error',
'...'
);
} else {
this.logger.log(
'info',
'...',
);
}
},
);
batchOffset+=batchSize;
}
......
private wait(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}