Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Drop old collector.prototyp implementation #434

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/collector.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Collector {
// Collector constructor
// expected - <number> | <string[]>, count or keys
constructor(expected) {
this.expectKeys = Array.isArray(expected) ? new Set(expected) : null;
this.expectKeys = Array.isArray(expected) ? expected : null;
this.expected = this.expectKeys ? expected.length : expected;
this.keys = new Set();
this.keys = [];
this.count = 0;
this.timer = null;
this.onDone = common.emptiness;
Expand All @@ -27,17 +27,17 @@ class Collector {
this.finalize(err, this.data);
return this;
}
if (this.expectKeys && !this.expectKeys.has(key)) {
if (this.expectKeys && !this.expectKeys.includes(key)) {
if (this.isDistinct) {
const err = new Error(UNEXPECTED_KEY + key);
this.finalize(err, this.data);
return this;
}
} else if (!this.keys.has(key)) {
} else if (!this.keys.includes(key)) {
this.count++;
}
this.data[key] = value;
this.keys.add(key);
this.keys.push(key);
if (this.expected === this.count) {
this.finalize(null, this.data);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/collector.functor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const collect = expected => {
if (!(isCount || isKeys)) throw new TypeError(TYPE_ERROR);
let keys = null;
if (isKeys) {
keys = new Set(expected);
keys = expected;
expected = expected.length;
}
let count = 0;
Expand All @@ -26,7 +26,7 @@ const collect = expected => {
const collector = (key, err, value) => {
if (isDone) return collector;
if (!isDistinct || !(key in data)) {
if (!isCount && !keys.has(key)) return collector;
if (!isCount && !keys.includes(key)) return collector;
count++;
}
if (err) {
Expand Down
10 changes: 5 additions & 5 deletions lib/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const COLLECT_CANCELED = 'Metasync: Collector cancelled';
// Data collector
// expected - <number> | <string[]>, count or keys
function Collector(expected) {
this.expectKeys = Array.isArray(expected) ? new Set(expected) : null;
this.expectKeys = Array.isArray(expected) ? expected : null;
this.expected = this.expectKeys ? expected.length : expected;
this.keys = new Set();
this.keys = [];
this.count = 0;
this.timer = null;
this.onDone = common.emptiness;
Expand All @@ -32,17 +32,17 @@ Collector.prototype.collect = function(key, err, value) {
this.finalize(err, this.data);
return this;
}
if (this.expectKeys && !this.expectKeys.has(key)) {
if (this.expectKeys && !this.expectKeys.includes(key)) {
if (this.isDistinct) {
const err = new Error(UNEXPECTED_KEY + key);
this.finalize(err, this.data);
return this;
}
} else if (!this.keys.has(key)) {
} else if (!this.keys.includes(key)) {
this.count++;
}
this.data[key] = value;
this.keys.add(key);
this.keys.push(key);
if (this.expected === this.count) {
this.finalize(null, this.data);
}
Expand Down
134 changes: 0 additions & 134 deletions lib/collector.prototype.js

This file was deleted.

4 changes: 2 additions & 2 deletions tests/load/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const COUNT = 1000000;
const benchmark = require('./benchmark.js');
const metasync = require('../../lib/collector.js');

const CollectPrototype = done => {
const Collect = done => {
const dc = metasync.collect(6);
dc.done(done);
let i = 0;
Expand All @@ -17,4 +17,4 @@ const CollectPrototype = done => {
setImmediate(() => dc.pick('6th', 'key' + ++i * 2));
};

benchmark.do(COUNT, [CollectPrototype]);
benchmark.do(COUNT, [Collect]);
20 changes: 0 additions & 20 deletions tests/load/collect.prototype.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/load/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ echo
echo Collector: 1mnl
node tests/load/collect.js
node tests/load/collect.class.js
node tests/load/collect.prototype.js
node tests/load/collect.functor.js