I need to check for debugging purposes if a promise is already resolved - something like p.isResolved(). Is there anyway to do this?
Asked
Active
Viewed 959 times
3
Bergi
- 572,313
- 128
- 898
- 1,281
someone235
- 527
- 2
- 6
- 21
-
Promise.state ? https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Promise – shershen Jul 21 '15 at 08:52
-
4@shershen That is not an exposed property. – loganfsmyth Jul 21 '15 at 15:51
1 Answers
4
Trigger a log when it is resolved or emit a event if you want it be handled somewhere else:
triggerMyPromiseMethod()
.then((response) => {
console.log('Promise resolved', response)
// continue...
})
.catch((err) => {
console.log('Something went wrong with my Promise', err)
})
Claudio Bredfeldt
- 1,413
- 16
- 27
-
agreed with @Claudio Bredfeldt the only way to debug your code is by using logs .. – Akriti Agarwal Jul 21 '15 at 09:01
-
So I understand by your answer that there's no way to check Promise's state outside of the promise context, right? – someone235 Jul 21 '15 at 09:17
-
2"By design, the instant state and value of a promise cannot be inspected synchronously from code, without calling the then() method.", MDN Promise Documentation – Claudio Bredfeldt Jul 21 '15 at 09:23