question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

About asynchronous getters/setters again

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:6
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
Ulrikopcommented, Mar 8, 2018

I would be happy to see that feature.

What’s the status?

0reactions
gaborszitacommented, Sep 12, 2021

This would be a great feature to add.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Async Getters and Setters. Is it Possible? | by David Barral
As you should know by now: Async functions always return a promise. If the return value of an async function is not explicitly...
Read more >
How would one do async JavaScript getters and setters?
The get and set function keywords seem to be incompatible with the async keyword. However, since async / await is just a wrapper...
Read more >
Async Operations in Property Getters and Setters in WPF
Dear Community: I've been using MVVM for long time (almost 4 years) in WPF and have been using async operations for that long...
Read more >
Tableau JavaScript API Concepts--Property Getters and Setters
Getters and setters are always functions that start with get or set . They can be called multiple times with little performance impact...
Read more >
How to create and use async properties - Hacking with Swift
Important: This is only possible on read-only computed properties – attempting to provide a setter will cause a compile error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found