-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromises.js
More file actions
64 lines (49 loc) · 1.07 KB
/
promises.js
File metadata and controls
64 lines (49 loc) · 1.07 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//Promise are available from ES6
/*
function addition(a, b){
return new Promise((resolve, reject) => {
try {
let total = a + b;
resolve(total)
} catch (error) {
reject(new Error(error))
}
})
}
addition(5, 5)
.then(total => { total += 10; console.log(total) })
.catch(error => { console.log(error) })
.finally(() => { console.log("Finally Nothing") })
*/
/*
console.log("Start")
setTimeout(() => {console.log("Timeout")}, 0)
Promise.resolve("Promise").then(res => console.log(res))
console.log("End")*/
/*
let promise = new Promise((resolve, reject) => {
let text = "Hello World";
//resolve(text)
reject(new Error("System Down!"))
});
promise
.then((result)=> {
console.log(result)
})
.catch((error) => {
console.log(error)
})
.finally(() => {
console.log('Finally, Sleep')
})
*/
async function main() {
await new Promise(resolve => {
setTimeout(() => {
console.log("Hello")
resolve()
}, 1000)
})
console.log("World")
}
main()