I have a function that returns a promise:
const validateForm = () => {
return new Promise((resolve, reject) => {
// code here takes time
return resolve('valid');
});
}
And I use this promise this way:
validateForm()
.then(function(result) {
console.log('form is valid');
})
console.log('line after promise');
I expect to see this output:
form is valid
line after promise
But I see this output:
line after promise
form is valid
How should I fix this code to get the first result? How freeze the code to not execute lines after promise until promise is either resolved or rejected?