index.js 409 B

123456789101112131415161718192021
  1. let count = 2;
  2. const calc1 = () => {
  3. return new Promise((res, rej) => {
  4. setTimeout(() => { count = count + 1; res(count) }, 2000)
  5. })
  6. }
  7. const calc2 = () => {
  8. return new Promise((res, rej) => {
  9. setTimeout(() => { count = count * 2; res(count) }, 3000)
  10. })
  11. }
  12. const calcNum = async() => {
  13. count = await calc2();
  14. count = await calc1();
  15. console.log(count)
  16. }
  17. calcNum();