Нello! I want to know if I'm overusing the await
keyword.
For a contrived example, let's say we need to get a filepath from some remote url, and then read a file with that filepath:
let requestHttpBody = async url => {/* ... returns http response body ... */};
let readFile = async filename => {/* ... returns file contents ... */};
let readFileBasedOnRequest = async () => {
let filename = await requestHttpBody('www.giveMeFileName.pls');
return await readFile(filename); // THIS LINE contains the `await` I'm concerned with!
};
Per the comment, this is where I'm unsure the await
keyword ought to be used. The data being returned is already the result of an async
function (in this case readFile
) and is already a promise. This code runs the same with or without that await
.
This code pattern is very common. Should I use await
?? Is there any well-accepted convention here? Are there differences depending on whether it's used, maybe subtleties in nextTick
timing? Or is this totally a matter of preference and not worth fretting about?