Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ijsong opened this issue Jun 10, 2013 · 4 comments
Closed

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

ijsong opened this issue Jun 10, 2013 · 4 comments

Comments

@ijsong
Copy link

ijsong commented Jun 10, 2013

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;
  }
});
@vendethiel
Copy link

That's how async works.

@ijsong
Copy link
Author

ijsong commented Jun 10, 2013

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

@vendethiel
Copy link

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

@dresende
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants