3 ms·
> I hadn't used finally much in JavaScript until recently, where I find myself using it like this in async functions: We can tell by your notation. Mixing try
by SavantIdiot 5y ago
> I hadn't used finally much in JavaScript until recently, where I find myself using it like this in async functions:
We can tell by your notation. Mixing try blocks with async/await and promises is mixing patterns and obscuring what you are attempting to accomplish.
- jaffathecake 5y agoNope. It was designed precisely for patterns like this.
- SavantIdiot 5y agoReally? I don't follow: why is try/catch/finally preferred over: async function someAsyncThing() { startSpinner(); await asyncWork() .catch(err => { if (err.name == 'AbortError') return; showErrorUI(); }) .finally(() => { stopSpinner(); }); } Should be identical, no? EDIT: Well, except that if there was more after asyncWork() the return in the try block would exit someAsyncThing, whereas the return in the catch block just returns from the catch. Is that his point?