I need to set a property of 'myObject' whose value will resolve after 2500 milliseconds. So I am making use of the Promise feature.
const promise = new Promise(function(resolve,reject) {
setTimeout(function(){
resolve("Success!");
}, 2500);
});
var myObject = {
status : promise.then(function(success) {
return success;
})
};
console.log(myObject.status);
when I run this I am getting in NodeJS.
Promise { <pending> }
All the examples I am finding in the internet shows how to call a callback method. None of them tells how to assign a value of a property from an Async call. I very much would like to solve this myself. It will be very helpful to just point me to a correct example.