nodejs-model icon indicating copy to clipboard operation
nodejs-model copied to clipboard

Asynchronous init?

Open ryleyb opened this issue 11 years ago • 0 comments

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

ryleyb avatar May 29 '14 16:05 ryleyb