-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallel.js
43 lines (36 loc) · 875 Bytes
/
parallel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function asyncGetAd(){
return new Promise((resolve, reject) => {
console.log("please check our new TV")
resolve({"adId": 1, "message": "checkout our new TV"})
})
}
function asyncSendAd(){
console.log("preparing to send async ad")
var ad = asyncGetAd()
return ad
}
async function syncSendAd(){
var ad = await asyncSendAd()
console.log("sending sync ad: " + JSON.stringify(ad))
return ad
}
function syncSendAd1(){
var ad = {}
Promise.all([asyncSendAd()]).then(r => {
console.log("[syncSend11] " + JSON.stringify(r))
ad = r
})
console.log("[syncSend12] " + JSON.stringify(ad))
return ad
}
function syncSendAd2(){
var task = new Promise((resolve, reject) => {
resolve({"addId": "ad01", "message": "stuff"})
})
return task
}
//syncSendAd()
//syncSendAd1()
syncSendAd2().then(ad => {
console.log(JSON.stringify(ad))
})