Skip to content

Commit

Permalink
Renaming taskManager map property
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyudmil Danailov authored and Lyudmil Danailov committed Jan 24, 2024
1 parent 40cc0d1 commit 5708174
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/task_manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class TaskManager {
constructor() {
this.map = {};
this.taskData = {};
this.queue;
this.buffer = [];
this.lastPushedToBuffer = 0;
Expand Down Expand Up @@ -39,22 +39,22 @@ class TaskManager {
}

#pushAllEligable() {
while (this.map[this.lastPushedToBuffer]) {
for (const data of this.map[this.lastPushedToBuffer]) {
while (this.taskData[this.lastPushedToBuffer]) {
for (const data of this.taskData[this.lastPushedToBuffer]) {
this.buffer.push(data);
this.lastProcessedPosition = {
primaryKey: this.buffer[this.buffer.length - 1].primaryKey,
blockNumber: this.buffer[this.buffer.length - 1].blockNumber
};
}

delete this.map[this.lastPushedToBuffer];
delete this.taskData[this.lastPushedToBuffer];
this.lastPushedToBuffer++;
}
}

handleNewData([key, newTransformedData]) {
this.map[key] = newTransformedData;
this.taskData[key] = newTransformedData;
this.#pushAllEligable();
}

Expand Down
4 changes: 2 additions & 2 deletions test/lib/task_manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('TaskManager', () => {
it('constructor initializes corresponding variables', () => {
const taskManager = new TaskManager();

assert.deepStrictEqual(taskManager.map, {});
assert.deepStrictEqual(taskManager.taskData, {});
assert.deepStrictEqual(taskManager.buffer, []);
assert.strictEqual(taskManager.lastPushedToBuffer, 0);
assert.strictEqual(taskManager.queue, undefined);
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('TaskManager', () => {
const exampleDataObject = [{ fromBlock: 1, toBlock: 10, data: [1, 2, 3] }];

taskManager.handleNewData([1, exampleDataObject]); // This [key, data] pair comes from the worker's work method
assert.deepStrictEqual(taskManager.map, {1: exampleDataObject});
assert.deepStrictEqual(taskManager.taskData, {1: exampleDataObject});
});

it('handleNewData() fills the buffer accordingly', () => {
Expand Down

0 comments on commit 5708174

Please sign in to comment.