Created
February 16, 2018 17:45
-
-
Save reinaldorauch/87d9ae8481cd8c0e49a4cc49c7d4ee9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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