13

Javascript promises: I JUST WANT THE FUCKING VALUE OF A PROMISE.

WHO THE FUCK THOUGHT PROMISES SIMPLIFIED ANYTHING?!

Comments
  • 4
    Use async
  • 2
    @devTea how?

    This is the only way I've figured it out so far:

    var gresult;
    Promise().then(function(result) {gresult = result; });
    return gresult;
  • 2
  • 3
    That's kinda the point of a promise. You don't know when the result will be available.
  • 2
    @toriyaki return will return undefined. You don't have the result until it's passed to your "then" function.
  • 3
    let result = await Promise(); works too. You need try catch to catch errors.
  • 1
    Search "npm wait for stuff"
  • 3
    It was all just a promise that it would simplify
  • 0
    Promises are great when all you want is to console.log things.
  • 0
  • 0
    Promises are literally the worst implementation of "asynchronous" programming that I have ever encountered. Example:

    const retrievedUserEmail: string | null = await (await userApi.getUserByEmail(email)).email
Add Comment