Skip to content

Commit 708f833

Browse files
committed
Add tasks
1 parent 8a5a6ac commit 708f833

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

JavaScript/4-bad.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
'use strict';
22

3+
// TODO: Refactor to respect SoC principle and
4+
// optimize JavaScript for V8
5+
36
const poolify = (factory, options, size, max) => {
4-
const instances = [];
5-
for (let i = 0; i < size; i++) {
6-
const instance = factory(...options);
7+
const instances = []; // Preallocate array
8+
for (let i = 0; i < size; i++) { // Use Array methods instead of loop
9+
const instance = factory(...options); // Avoid array destructuring
710
instances.push(instance);
811
}
912

10-
return (instance) => {
11-
if (instance) {
13+
return (instance) => { // Respect SoC and SOLID/SRP
14+
if (instance) { // Avoid if-statement
1215
if (instances.length < max) {
1316
instances.push(instance);
1417
}
1518
}
16-
instance = instances.pop();
19+
instance = instances.pop(); // Do not reassign incoming parameters
1720
if (!instance) instance = factory(...options);
1821
return instance;
1922
};

JavaScript/Tasks.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Pool tasks
2+
3+
1. Optimize `4-bad.js`, see TODOs in the file; check solution if `4-improved.js`
4+
2. Rewrite `4-improved.js` to class syntax
5+
3. Implement async instance acquisition in closure version with queue and callbacks
6+
4. Implement async instance acquisition in classes version with queue and callbacks
7+
5. Rewrite acquisition to promises in closure version
8+
6. Rewrite acquisition to promises in classes version

0 commit comments

Comments
 (0)