-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync.js
More file actions
44 lines (34 loc) · 733 Bytes
/
async.js
File metadata and controls
44 lines (34 loc) · 733 Bytes
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
43
44
//async fn always return a promise;
async function name() {
console.log("hello");
}
//return promise;
//await pauses the execution of surroundings until asyncs fn promise is setteled;
//can only be used to in async fun;
function api(){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log("data is fetched");
resolve("success");
},2000)
})
}
async function n() {
await api();
await api();
}
n();
function prob(dataid){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
console.log(dataid);
resolve("doneee")
},5000)
})
}
async function s() {
await prob(1);
await prob(2);
await prob(3);
}
s();