Skip to content

Instantly share code, notes, and snippets.

@willie-hung
Last active July 12, 2023 18:44
Show Gist options
  • Save willie-hung/9c5f8b47bf531821a646464452acb1e3 to your computer and use it in GitHub Desktop.
Save willie-hung/9c5f8b47bf531821a646464452acb1e3 to your computer and use it in GitHub Desktop.
post_6
function fetchData(): Promise<string> {
return new Promise((resolve, reject) => {
setTimeout(() => {
const data = "Here are some mock data 🤡";
if (data) {
resolve(data);
} else {
reject("Data not found");
}
}, 2000);
});
}
fetchData()
.then((data) => {
console.log("Received data:", data);
})
.catch((error) => {
console.error("Error:", error);
});
// Output: Received data: Here are some mock data 🤡
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment