Is your feature request related to a problem? Please describe.
In most cases, you should just await the promise and get its value, even if the promise has already resolved. However, it could sometimes be useful to get the state of the promise. For example, as an optimization to only do a heavy operation if the promise in a certain state or for assertions when writing tests.
Describe the solution you'd like
There used to be process.binding('util').getPromiseDetails(promise)
, but it was removed in Node.js 16. I suggest exposing a util.promiseState(promise)
method which would return 'pending' | 'fulfilled' | 'rejected'
depending on the promise state.
Describe alternatives you've considered
I have made a package for this, but it depends on parsing util.inspect()
output which is a bit fragile.
fregante, Richienb, szmarczak, rafifos, sadn1ck and 23 moreLemminghfregante, sadn1ck, jopemachine and wmestrom
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4