-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
26 lines (20 loc) · 713 Bytes
/
index.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
(function(context) {
function demo() {
console.log('\n\nPROMISES');
// a promise generator function, returning new promise
// which executes a setTimeout resolving after 1 sec
const timeoutPromise = () => new Promise((resolve, reject) => { setTimeout(resolve, 1000) });
// simple promise and then
timeoutPromise()
.then(() => console.log('Yo!'));
// promise chaining
timeoutPromise()
.then(() => timeoutPromise())
.then(() => console.log('YoYo!'));
timeoutPromise()
.then(() => timeoutPromise())
.then(() => timeoutPromise())
.then(() => console.log('YoYoYo!'));
};
(context || this).demoLibs['promises'] = demo;
})(window);