Welcome to the Linux Foundation Forum!

Perhaps a `return` is missed the model.js file for lab 5.1.

Posts: 58
edited January 2023 in LFW212 Class Forum

In the model.js file, the implementation of read method is:

  1. function read (id, cb) {
  2. if (id === 'c060') {
  3. setImmediate(() => cb(Error('unknown')))
  4. /* return // I think we missed the return statement here. */
  5. }
  6. if (!(db.hasOwnProperty(id))) {
  7. const err = Error('not found')
  8. err.code = 'E_NOT_FOUND'
  9. setImmediate(() => cb(err))
  10. return
  11. }
  12. setImmediate(() => cb(null, db[id]))
  13. }

In the callback of the first setImmediate function, there should be a return at the end of it IMHO. If the id === 'c060', setImmediate function will be called twice which in turn will invoke cb twice for a single request.

I am not sure whether this is on purpose. But in a practical situation, I think this is not expected. Thoughts?

Best Answer

  • Posts: 160
    Answer ✓

    @krave I think you're right, I think a return is needed, I'll address this in the next major update

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training