top | item 44485199

(no title)

neallindsay | 7 months 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)

  }

}

discuss

order

fastball|7 months ago

Easier to write. But there is a case to be made that code which can be understood without understanding somewhat esoteric language internals is superior.

neallindsay|7 months ago

I 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.

yeasku|7 months ago

Is code wrote for a broken server.

It makes no sense even with common js idiom.