Skip to content

Instantly share code, notes, and snippets.

@jagsbyteinception
Created May 21, 2020 21:20
Show Gist options
  • Save jagsbyteinception/d9b006cfed39d5eb4cdda7c5189a3fe5 to your computer and use it in GitHub Desktop.
Save jagsbyteinception/d9b006cfed39d5eb4cdda7c5189a3fe5 to your computer and use it in GitHub Desktop.
nodejs - await async in loop
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