The Promise whose state is to be determined.
A Promise that resolves to a string representing the state of the input Promise:
If the input is not a Promise.
const myPromise = new Promise(resolve => setTimeout(() => resolve('done'), 1000));
// Check state immediately
promiseState(myPromise).then(state => console.log(state)); // Logs: 'pending'
// Check state after 2 seconds
setTimeout(() => {
promiseState(myPromise).then(state => console.log(state)); // Logs: 'resolved'
}, 2000);
This function uses Promise.race()
internally to determine the state of the input Promise.
It does not affect the execution or result of the input Promise in any way.
Note that the state of a Promise can change from 'pending' to either 'resolved' or 'rejected', but once it's settled (either 'resolved' or 'rejected'), it cannot change again.
Determines the current state of a Promise.