Welcome to the Linux Foundation Forum!

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

Options
krave
krave Posts: 58
edited January 2023 in LFW212 Class Forum

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

function read (id, cb) {
  if (id === 'c060') {
    setImmediate(() => cb(Error('unknown')))
    /* return  // I think we missed the return statement here. */
  }
  if (!(db.hasOwnProperty(id))) {
    const err = Error('not found')
    err.code = 'E_NOT_FOUND'
    setImmediate(() => cb(err))
    return
  }
  setImmediate(() => cb(null, db[id]))
}

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

  • xdxmxc
    xdxmxc Posts: 139
    Answer ✓
    Options

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

Categories

Upcoming Training