Skip to content

Instantly share code, notes, and snippets.

@bu7ch
Created October 22, 2019 08:49
Show Gist options
  • Save bu7ch/3d948b63c703ea84a546d3a070da5bc1 to your computer and use it in GitHub Desktop.
Save bu7ch/3d948b63c703ea84a546d3a070da5bc1 to your computer and use it in GitHub Desktop.
async function notifyCustomer() {
const customer = await getCustomer(1);
console.log('Customer: ', customer);
if (customer.isGold) {
const movies = await getTopMovies();
console.log('Top movies: ', movies);
await sendEmail(customer.email, movies);
console.log('Email sent...');
}
}
notifyCustomer();
function getCustomer(id) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
id: 1,
name: 'Linux Torvald',
isGold: true,
email: 'email'
});
}, 4000);
});
}
function getTopMovies() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(['movie1', 'movie2']);
}, 4000);
});
}
function sendEmail(email, movies) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 4000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment