Skip to content

Asynchronous init? #9

@ryleyb

Description

@ryleyb

How do I deal with the case where I want to do something asynchronously in my model.init function?

For instance:

myModel.init = function(instance){
  exec('ls -l',function(err,stdout,stderr){
    //error checking etc
    instance.files(stdout);
  }
}

So far my solution has been to use a promise as the contents of that particular attribute, but that doesn't seem ideal. Is there a better way?

In my controller, it would be nice if I could do this:

Q.when(myModel.create()).then(.... //etc

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