0

Is it possible to store a value from a promise to a outside variable

 var hwid;
    getHWID().then(id => {
    console.log(id)
    })

I want the id in the hwid variable so i can check it against a mysql database

  • `await` the Promise – CertainPerformance Oct 12 '19 at 22:58
  • 1
    Yes, it's possible, [but pointless](https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron). Just store the promise itself in the variable. – Bergi Oct 12 '19 at 23:05
  • Of course, you can, but since Promises are all about time, how do you know when the value will be available? Now you need some state that tells you wether the value is already available or not, and maybe some EventDispatcher so you can register to an event and get notified when `hwid` is available, ... you see a pattern? You're basically re-building a Promise. Just use the Promise – Thomas Oct 12 '19 at 23:06

0 Answers0