Skip to content

Instantly share code, notes, and snippets.

@reinaldorauch
Created February 16, 2018 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinaldorauch/87d9ae8481cd8c0e49a4cc49c7d4ee9d to your computer and use it in GitHub Desktop.
Save reinaldorauch/87d9ae8481cd8c0e49a4cc49c7d4ee9d to your computer and use it in GitHub Desktop.
function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), ms);
});
}
// Aí vc adiciona na corrente de promises na função de insersão do banco:
function bulkInsert(conn, data) {
const sql = 'INSERT INTO table (fielda, fieldb, fieldc) VALUES ?';
return mysqlQuery(sql, data.map(mapObjectIntoArray))
.then(() => timeout(200)); // vai esperar 200 ms pra retornar a promise e continuar o map chamado acima no stack;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment