index.js 425 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. calc2().then(result => {
  13. count = result;
  14. calc1().then(result => {
  15. count = result;
  16. console.log(count);
  17. })
  18. })