How to access the value of a promise?

后端 未结 12 2603
予麋鹿
予麋鹿 2020-11-22 06:55

I\'m looking at this example from Angular\'s docs for $q but I think this probably applies to promises in general. The example below is copied verbatim from the

12条回答
  •  暖寄归人
    2020-11-22 07:09

    pixelbits answer is correct and you should always use .then() to access the value of a promise in production code.

    However, there is a way to access the promise's value directly after it has been resolved by using the following unsupported internal node.js binding:

    process.binding('util').getPromiseDetails(myPromise)[1]
    

    WARNING: process.binding was never meant to be used outside of nodejs core and the nodejs core team is actively looking to deprecate it

    https://github.com/nodejs/node/pull/22004 https://github.com/nodejs/node/issues/22064

提交回复
热议问题