mongoose virtual setter - how to know its finished?

Is there a way to know when a mongoose virtual setter is done 'setting'?

for example:

schema.virtual('file").set(function(fileObj) {
    var that = this;
    var dst = '/somewhere/else.txt';
    fs.rename(fileObj.path, dst, function(err) {
       that.set("file.path", dst);
       that.markModified('file');
       //here i would like to know that the setter finished doing stuff so can potentially save my object
    } 
});

The problem i face is that when i set the file property of my mongoose model, i have no way to know when the rename is done, so when i save my object, there is a chance that the setter code hasnt finished running.

I know i can just create a method on the model that sets the file, but is there a way to do it in the setter?

Your options are to either:

  1. Use fs.renameSync instead of fs.rename as virtual setter methods must be synchronous.
  2. Switch to an instance method (as you mention) which could accept a callback parameter that your method calls when fs.rename completes.