Advertisement
Guest User

Untitled

a guest
May 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function delay(t, v) {
  2. return new Promise(function (resolve) {
  3. setTimeout(resolve.bind(null, v), t)
  4. });
  5. }
  6.  
  7. Promise.prototype.delay = function (t) {
  8. return this.then(function (v) {
  9. return delay(t, v);
  10. });
  11. }
  12.  
  13. function solve (time) {
  14. Promise.resolve("hello1").delay(time).then(function (v) {
  15. console.log("111111");
  16. }).then(function (v) {
  17. setTimeout(() => {
  18. console.log("222222");
  19. }, time);
  20. }).delay(time).then(function (v) {
  21. setTimeout(() => {
  22. console.log("333333");
  23. }, time);
  24. }).delay(time).then(function (v) {
  25. setTimeout(() => {
  26. console.log("444444");
  27. }, time);
  28. })
  29. }
  30.  
  31. solve(2000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement