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 fs.readFile(file, "utf8");
console.log(contents);
});
}
printFiles();
This code does work, but could something go wrong with this? I had someone tell me that you're not supposed to use async
/await
in a higher-order function like this, so I just wanted to ask if there was any issue with this. I am an amateur game developer, and I've been reading a lot on how computer graphics rendering works lately. I was reading on the Z-buffer recently and I can't quite seem to be able to wrap my head around what exactly the Z-buffer looks like in terms of memory. It's described to contain depth information for each fragment that will be drawn on-screen, and that modern Z-buffers have 32-bits, so would that mean that on a, let's say, 1920x1080 screen it'd be just above 8MB (1920 1080 32) per frame?
I still don't quite understand what this value would be to a GPU (maybe it can crunch it easily), or if this value is even correct. Most demostrative implementations I found implement the Z-buffer as a simple array with size (height * width), so I'm basing myself off of that.