-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
41 lines (34 loc) · 782 Bytes
/
test.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*jshint esversion: 6 */ // Help out our linter
GlobalVar = 1;
timesPlusOneWithWait();
GlobalVar = 1;
for (let i=0; i<3; i++) {
timesPlusOne(i)
.then((newI) => timesGlobal(newI))
.then((bignum) => console.log(bignum));
}
GlobalVar += 100;
async function timesPlusOneWithWait() {
for (let i=0; i<3; i++) {
try {
let newI = await timesPlusOne(i);
let bignum = await timesGlobal(newI);
console.log(bignum);
}
catch(e) { console.log(e.message);}
}
GlobalVar += 100;
}
function timesPlusOne(i) {
return new Promise(function(resolve) {
GlobalVar += 1;
let newI = i * (i+1);
resolve(newI);
});
}
function timesGlobal(i) {
return new Promise(function(resolve) {
let newI = i * GlobalVar;
resolve(newI);
});
}