I'm fairly new to Javascript and am looking for a little bit of clarification surrounding async/await when it comes to how/the order which Promises are resolved.
Say I have an async function, let's call it foo, that retrieves something and then writes it to a file using the fs.promises library.
const foo = async () => {
const x = await getX();
fs.promises.writeFile(path, x); //do I need to await this?};
I also have another async function that will call foo, and then do something with the file contents after they are written -- display it on a webpage, make a calculation, whatever.
const doSomething = async () => {
await foo(); //want to make sure foo resolves before calling otherFileFunc
otherFileFunc(); };
I want to ensure that the file contents have written, i.e. the promise of writeFile is resolved, before otherFileFunc executes. Is awaiting foo enough here, or can the promise of foo resolve before the promise of writeFile resolves? Should I await writeFile within foo to ensure this behavior, OR is the entire promise resolution of foo dependent on the promise of writeFile resolving and therefore awaiting it is superfluous?
Thank you!