Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /*
  2. Requirement : Prepare a coffee
  3. Steps :
  4. 1. Go and get milk from shop
  5. 2. Boil the milk
  6. 3. Mix sugar and coffee => Tasty coffee ready :-)
  7. */
  8.  
  9. const goGetMilk = function () {
  10. return new Promise(function (resolve, reject) {
  11. setTimeout(
  12. function () {
  13. console.log('Step 1 - I got the milk from shop');
  14. resolve();
  15. },
  16. 1000
  17. )
  18. });
  19. };
  20.  
  21.  
  22. const boilMilk = function () {
  23. return new Promise(function (resolve, reject) {
  24. setTimeout(
  25. function () {
  26. console.log('Step 2 - Milk is hot');
  27. resolve();
  28. },
  29. 2000
  30. )
  31. });
  32. };
  33.  
  34. const mixSugarAndCoffeePowder = function () {
  35. return new Promise(function (resolve, reject) {
  36. setTimeout(
  37. function () {
  38. console.log('Step 3 - Coffee powder and Sugar Added');
  39. resolve()
  40. },
  41. 500
  42. )
  43. });
  44. };
  45.  
  46. async function makeCoffee() {
  47. await goGetMilk(); /* 1 */
  48. await boilMilk(); /* 2 */
  49. await mixSugarAndCoffeePowder(); /* 3 */
  50. }
  51.  
  52. makeCoffee();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement