Created
October 22, 2019 08:49
-
-
Save bu7ch/3d948b63c703ea84a546d3a070da5bc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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