How do I convert an existing callback API to promises?

I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback … window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { … } request(function() { // change happened … }); 3. Node style callback (“nodeback”): … Read more

Using async/await with a forEach loop

Are there any issues with using async/await in a forEach loop? I’m trying to loop through an array of files and await on the contents of each file. import fs from ‘fs-promise’ async function printFiles () { const files = await getFilePaths() // Assume this works fine files.forEach(async (file) => { const contents = await … Read more