Skip to content

About asynchronous getters/setters again #4227

@bigslycat

Description

@bigslycat

I have read the two discussions (#2571 and #517) that relate to this opportunity, and still do not see any reason to abandon it. Why not? Even if Mongoose should maintain compatibility with the ES5, this does not prevent to check that the setter returns to us. Watch this pseudo-code:

if (setterResult.constructor.name === 'Promise' && setterResult.then) {
  promisesArray.push(setterResult.then(
    value => {
      return {
        path: path,
        value: value
      };
    },
    err => {
      return err;
    }
  ));
}

// ...

if (promisesArray.length){
  return Promise.all(promisesArray).then(
    results => {
      for (let result of results) {
        // Do anything with it
      }
      // Do anything with all fields
      return this.save();
    },
    errors => {
      for (let err of errors) {
        // Do anything with it
      }
      return errors;
    }
  );
} else {
  // Do anything with all fields
  return this.save();
}

So why not? This is a very useful feature, and it will join naturally in existing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions