-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromise.js
More file actions
32 lines (29 loc) · 841 Bytes
/
promise.js
File metadata and controls
32 lines (29 loc) · 841 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
let testPromise = new Promise(function (resolve, reject) {
let sucessFlag = true;
if (sucessFlag) {
//invoke resolve function passed
resolve("success promise completed");
} else {
reject("ERROR , work could not be completed");
}
})
// Create a function that returns a Promise and resolve when calling the function.
const treasure = () => {
return new Promise((resolve, reject) => {
const success = true;
setTimeout(() => {
success ? resolve("Hii this is resolved promise") : reject("Hii this is Rejected promise")
}, 1000)
})
}
treasure().then(res => {
console.log('Response ==', res)
}).catch(err => {
console.log('Error ==', err)
}).finally(() => {
console.log('final block')
}).then(res => {
console.log('Response ==', res)
}).catch(err => {
console.log('errrr bllock last')
})