5 ms·
Promises in JS make this stuff much easier (at least to my mind): const lockify = f => { let lock = Promise.resolve() return (...args) => { const re
by neallindsay 1y ago
Promises in JS make this stuff much easier (at least to my mind):
const lockify = f => {
let lock = Promise.resolve()
return (...args) => {
const result = lock.then(() => f(...args))
lock = result.catch(() => {})
return result.then(v => v)
}
}
- fastball 1y agoEasier to write. But there is a case to be made that code which can be understood without understanding somewhat esoteric language internals is superior.
- yeasku 1y agoIs code wrote for a broken server. It makes no sense even with common js idiom.
- fastball 1y agoOk, but that's not relevant to my point. Plus, in real life you do need to interact with broken servers – that doesn't mean you should make your code less readable as well.
- neallindsay 1y agoI guess "esoteric" is in the eye of the beholder, but Promises seem a lot easier than the old callback style we used to use for asynchronous operations.