2 ms·
Wait, what? The author sees this code and realizes it's unnecessarily serial: save('userData', userData) .then(() => save('session', sessionPrefence
by spankalee 2y ago
Wait, what?
The author sees this code and realizes it's unnecessarily serial:
save('userData', userData)
.then(() => save('session', sessionPrefences))
.then(() => ({ userData, sessionPrefences })
But doesn't see that the async/await version is serial, even though it's arguably even _more_ obvious?
await save('userData', userData);
await save('session', sessionPrefences);
return { userData, sessionPrefences }
The transform to being parallel is pretty easy to read too:
await Promise.all([
save('userData', userData),
save('session', sessionPrefences)
]);
return { userData, sessionPrefences }
On top of that, the try/catch section is out of date. try/catch does not deoptimize the block in modern engines, and async/await absolutely integrates better with try/catch for much more bulletproof error handling.