-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpromise.js
More file actions
25 lines (22 loc) · 791 Bytes
/
promise.js
File metadata and controls
25 lines (22 loc) · 791 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
const firstPromise = new Promise(function (resolve, reject) {
setTimeout(() => reject("First Promise: Something went wrong!"), 1000);
});
firstPromise.then(function () {
console.log("Succeed!");
}, function (errorMessage) {
console.log(errorMessage);
});
console.log("Waiting response...");
const secondPromise = new Promise(function (resolve, reject) {
resolve("Second Promise: Success :)");
});
secondPromise.then((message) => console.log(message));
const thirdPromise = new Promise(function (resolve, reject) {
setTimeout(() => reject("Third Promise: An error is occured!"), 1500);
setTimeout(() => resolve("Third Promise: Congrats!!"), 2000); // ignored
});
thirdPromise.then(
(message) => console.log(message)
).catch(
(error) => console.log(error)
);