Is anyone so kind to advise how can I make .finally message: "End of promise" appear at the end of the code instead of at the beginning?
const posts = [
{ title: "Post One", body: "This is post one" },
{ title: "Post Two", body: "This is post two" },
];
function getPosts() {
setTimeout(() => {
posts.forEach((post) => {
console.log(post.title, post.body);
});
}, 1000);
}
function createPostPromise(post) {
return new Promise((resolve, reject) => {
const error = false;
if (!error) {
setTimeout(() => {
posts.push(post);
resolve(true);
});
} else {
reject("Error: Something went wrong");
}
}, 2000);
}
createPostPromise({ title: "Post Three", body: "This is post three" })
.then(getPosts)
.catch((err) => console.log(err))
.finally(() => {
console.log("End of promise");
});