I have a pure JavaScript Promise (built-in implementation or poly-fill):
(我有一个纯JavaScript Promise(内置实现或poly-fill):)
var promise = new Promise(function (resolve, reject) { /* ... */ });
From the specification , a Promise can be one of:
(根据规范 ,Promise可以是以下之一:)
- 'settled' and 'resolved'
(“解决”和“解决”)
- 'settled' and 'rejected'
(“解决”和“拒绝”)
- 'pending'
(“待定”)
I have a use case where I wish to interrogate the Promise synchronously and determine:
(我有一个用例,希望同步查询Promise并确定:)
I know that I can use #then()
to schedule work to be performed asynchronously after the Promise changes state.
(我知道可以在Promise更改状态后使用#then()
安排要异步执行的工作。)
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?(我该如何实现?)
ask by jokeyrhyme translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…