Skip to content

Commit 2700a7b

Browse files
committed
Convert IIFE to async main
1 parent accea3d commit 2700a7b

5 files changed

Lines changed: 23 additions & 15 deletions

File tree

‎JavaScript/1-iterator.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ const asyncIterator = {
55
async next() {
66
return {
77
value: this.counter++, // current value
8-
done: this.counter > 3 // boolean
8+
done: this.counter > 3, // boolean
99
};
10-
}
10+
},
1111
};
1212

1313
const step1 = asyncIterator.next();

‎JavaScript/2-iterable.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const iterable = {
77
async next() {
88
return {
99
value: i++,
10-
done: i > 3
10+
done: i > 3,
1111
};
12-
}
12+
},
1313
};
1414
return iterator;
15-
}
15+
},
1616
};
1717

1818
// Usage
@@ -24,8 +24,10 @@ const step3 = iterator.next();
2424
const step4 = iterator.next();
2525
console.log({ step1, step2, step3, step4 });
2626

27-
(async () => {
27+
const main = async () => {
2828
for await (const step of iterable) {
2929
console.log({ step });
3030
}
31-
})();
31+
};
32+
33+
main();

‎JavaScript/3-class.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class Counter {
1515
async next() {
1616
const item = {
1717
value: i,
18-
done: i >= end
18+
done: i >= end,
1919
};
2020
i += step;
2121
return item;
22-
}
22+
},
2323
};
2424
return iterator;
2525
}
@@ -36,8 +36,10 @@ const step3 = iterator.next();
3636
const step4 = iterator.next();
3737
console.log({ step1, step2, step3, step4 });
3838

39-
(async () => {
39+
const main = async () => {
4040
for await (const step of iterable) {
4141
console.log({ step });
4242
}
43-
})();
43+
};
44+
45+
main();

‎JavaScript/4-generator.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ const gen = async function* () {
2020
});
2121
}
2222

23-
(async () => {
23+
const main = async () => {
2424
const iterable = gen();
2525
for await (const step of iterable) {
2626
console.log({ step });
2727
}
28-
})();
28+
};
29+
30+
main();

‎JavaScript/5-yield.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ const gen = async function* () {
1616
});
1717
}
1818

19-
(async () => {
19+
const main = async () => {
2020
const iterable = gen();
2121
for await (const step of iterable) {
2222
console.log({ step });
2323
}
24-
})();
24+
};
25+
26+
main();

0 commit comments

Comments
 (0)