I asked this question on StackOverflow.
I have a pure JavaScript Promise (built-in implementation or poly-fill):
var promise = new Promise(function (resolve, reject) { /* ... */ });
From the specification, a Promise can be one of:
- ‘settled’ and ‘resolved’
- ‘settled’ and ‘rejected’
- ‘pending’
I have a use case where I wish to interrogate the Promise synchronously and determine:
- is the Promise settled?
- if so, is the Promise resolved?
I know that I can use
#then()
to schedule work to be performed asynchronously after the Promise changes state. I am NOT asking how to do this.This question is specifically about synchronous interrogation of a Promise’s state. How can I achieve this?
There is apparently no API for this as part of the specification for native Promises.
Some user-land implementations of Promises do offer this (e.g. jQuery). Can we please get a standard API for this purpose in native Promise?