码迷,mamicode.com
首页 > Web开发 > 详细

js async06

时间:2020-01-16 12:16:06      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:time   pre   after   star   color   one   get   rom   ons   

 1 function resolveAfter2Seconds() {
 2   console.log(‘slow start at: ‘ + new Date().getSeconds())
 3   return new Promise(resolve => {
 4     setTimeout(() => {
 5       resolve(‘slow‘)
 6       console.log(‘slow done at: ‘ + new Date().getSeconds())
 7     }, 2000 )
 8   })
 9 }
10 function resolveAfter1Second() {
11   console.log(‘fast start at: ‘ + new Date().getSeconds())
12   return new Promise(resolve => {
13     setTimeout(() => {
14       resolve(‘fast‘)
15       console.log(‘fast done at: ‘ + new Date().getSeconds())
16     }, 1000 )
17   })
18 }
19 var parallelPromise = function() {
20   console.log(‘==PARALLEL WITH Promise.then== at: ‘ + new Date().getSeconds())
21   resolveAfter2Seconds().then(message => console.log(message + " at: " + new Date().getSeconds()))
22   resolveAfter1Second().then(message => console.log(message + " at: " + new Date().getSeconds()))
23 }
24 
25 parallelPromise()

//

==PARALLEL WITH Promise.then== at: 49
slow start at: 49
fast start at: 49
fast done at: 50
fast at: 50
slow done at: 51
slow at: 51

js async06

标签:time   pre   after   star   color   one   get   rom   ons   

原文地址:https://www.cnblogs.com/anch/p/12200437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!