Created
May 21, 2020 21:20
-
-
Save jagsbyteinception/d9b006cfed39d5eb4cdda7c5189a3fe5 to your computer and use it in GitHub Desktop.
nodejs - await async in loop
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
res.write('start'); | |
var files = searchRecursive(config.app.publicPath, '.scss'); | |
//foreach is not promise-aware. so use map | |
//map return promises | |
var promises = await files.map(async(scss)=>{ | |
var css = scss.replace('.scss','.min.css'); | |
var map = scss.replace('.scss','.min.css.map'); | |
var result = await sassAsyncRender(scss,css,map); | |
res.write(JSON.stringify({result})); | |
}); | |
await Promise.all(promises); //wait for all promise to complete | |
res.write('end'); | |
res.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment