Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <script type="text/javascript">
  7.  
  8. var p1 = new Promise(function(resolve,reject){
  9.  
  10. setTimeout(function(){
  11. console.log('End timeout');
  12. resolve('ok traitement');
  13. },2000);
  14.  
  15. });
  16.  
  17.  
  18.  
  19. p1
  20. .then(function(res){
  21.  
  22. return new Promise(function(resolve,reject){
  23. setTimeout(function(){
  24. console.log('get '+res);
  25. resolve('ok '+'get '+res);
  26. },2000);
  27. });
  28.  
  29. })
  30. .then(function(res){
  31. console.log("final : "+res);
  32.  
  33. });
  34. // ---------------------------------------------------------------
  35. var p2 = new Promise(function(resolve,reject){
  36. setTimeout(function(){
  37. console.log('p2');
  38. resolve('ok p2');
  39. },2000);
  40. });
  41. var p3 = new Promise(function(resolve,reject){
  42. setTimeout(function(){
  43. console.log('p3');
  44. resolve('ok p3');
  45. },4000);
  46. });
  47.  
  48.  
  49.  
  50. Promise.all([p2,p3]).then(function(data){
  51. console.dir(data);
  52. });
  53.  
  54.  
  55. </script>
  56. </head>
  57. <body>
  58.  
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement