Skip to content

load function doesn't return value... #194

Closed

Description

@ijsong

File: ORM.js
Function: ORM.prototype.load
Issue:
Function load does not return any value when it is success. It is OK when model is loaded with instance of connect function. However, it has some problem using with express function.
In below code, novalue has undefined, because the load function doesn't return. It results in work-around code such as models.user = db.models.user;.

However, it'd be better that models.user = db.load ....

exports.db = orm.express(options, {
  define: function (db, models) {
    var novalue = db.load('./models/user', function (err) {
      if (err) {
        console.log('Fail to load model');
        throw err;
      }
      return db.models.user; /* HAVE NO EFFECT */
    });
    models.user = db.models.user;
  }
});

Activity

  1. vendethiel commented on Jun 10, 2013

    @vendethiel

    That's how async works.

  2. ijsong commented on Jun 10, 2013

    @ijsong
    Author

    The load is blocking call. So the caller is stopped until require(file)(this, cb) is done.

  3. vendethiel commented on Jun 10, 2013

    @vendethiel

    That's true, my bad. I blindly assumed that since it uses a callback.

  4. dresende commented on Jun 11, 2013

    @dresende
    Owner

    Still, it's async. After the require, it will call the module and expect a callback to be invoked, which you could for example use to load things from the network, database, ...

    You can of course use it sync, I'm going to change it to return the returned value from the function so you can use it if you want, but that's entirely up to you to create that logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions