Skip to content

Commit 9028730

Browse files
committed
Renames the instances of Parallel too.
1 parent 360e088 commit 9028730

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

lib/thread.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,27 @@
7474
maxWorkers: isNode ? require('os').cpus().length : 4
7575
};
7676

77-
function Parallel(data, options) {
77+
function Thread(data, options) {
7878
this.data = data;
7979
this.options = extend(defaults, options);
8080
this.operation = new Operation();
8181
this.operation.resolve(null, this.data);
8282
}
8383

84-
Parallel.getWorkerSource = function (cb) {
84+
Thread.getWorkerSource = function (cb) {
8585
if (isNode) {
8686
return 'process.on("message", function(e) {process.send(JSON.stringify((' + cb.toString() + ')(JSON.parse(e).data)))})';
8787
} else {
8888
return 'self.onmessage = function(e) {self.postMessage((' + cb.toString() + ')(e.data))}';
8989
}
9090
};
9191

92-
Parallel.prototype.spawn = function (cb) {
92+
Thread.prototype.spawn = function (cb) {
9393
var that = this;
9494
var newOp = new Operation();
9595
this.operation.then(function () {
9696
var wrk = new Worker(that.options.path);
97-
wrk.postMessage(Parallel.getWorkerSource(cb));
97+
wrk.postMessage(Thread.getWorkerSource(cb));
9898
wrk.postMessage(that.data);
9999
wrk.onmessage = function (msg) {
100100
wrk.terminate();
@@ -106,10 +106,10 @@
106106
return this;
107107
};
108108

109-
Parallel.prototype._spawnMapWorker = function (i, cb, done) {
109+
Thread.prototype._spawnMapWorker = function (i, cb, done) {
110110
var that = this;
111111
var wrk = new Worker(that.options.path);
112-
wrk.postMessage(Parallel.getWorkerSource(cb));
112+
wrk.postMessage(Thread.getWorkerSource(cb));
113113
wrk.postMessage(that.data[i]);
114114
wrk.onmessage = function (msg) {
115115
wrk.terminate();
@@ -118,7 +118,7 @@
118118
};
119119
};
120120

121-
Parallel.prototype.map = function (cb) {
121+
Thread.prototype.map = function (cb) {
122122
if (!this.data.length) {
123123
return this.spawn(cb);
124124
}
@@ -144,10 +144,10 @@
144144
return this;
145145
};
146146

147-
Parallel.prototype._spawnReduceWorker = function (data, cb, done) {
147+
Thread.prototype._spawnReduceWorker = function (data, cb, done) {
148148
var that = this;
149149
var wrk = new Worker(that.options.path);
150-
wrk.postMessage(Parallel.getWorkerSource(cb));
150+
wrk.postMessage(Thread.getWorkerSource(cb));
151151
wrk.postMessage(data);
152152
wrk.onmessage = function (msg) {
153153
wrk.terminate();
@@ -156,7 +156,7 @@
156156
};
157157
};
158158

159-
Parallel.prototype.reduce = function (cb) {
159+
Thread.prototype.reduce = function (cb) {
160160
if (!this.data.length) {
161161
throw new Error('Can\'t reduce non-array data');
162162
}
@@ -188,7 +188,7 @@
188188
return this;
189189
};
190190

191-
Parallel.prototype.then = function (cb, errCb) {
191+
Thread.prototype.then = function (cb, errCb) {
192192
var that = this;
193193
var newOp = new Operation();
194194
this.operation.then(function () {
@@ -200,8 +200,8 @@
200200
};
201201

202202
if (isNode) {
203-
module.exports = Parallel;
203+
module.exports = Thread;
204204
} else {
205-
self.Parallel = Parallel;
205+
self.Thread = Thread;
206206
}
207207
})();

test/api.spec.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
describe('API', function () {
22
it('should be a constructor', function () {
3-
var Parallel = require('../lib/thread.js');
4-
expect(Parallel).toEqual(jasmine.any(Function));
3+
var Thread = require('../lib/thread.js');
4+
expect(Thread).toEqual(jasmine.any(Function));
55
});
66

77
it('should define a .then(cb) function', function () {
8-
var Parallel = require('../lib/thread.js');
9-
var p = new Parallel([1, 2, 3]);
8+
var Thread = require('../lib/thread.js');
9+
var p = new Thread([1, 2, 3]);
1010
expect(p.then).toEqual(jasmine.any(Function));
1111
});
1212

1313
it('should define a .map(cb) function', function () {
14-
var Parallel = require('../lib/thread.js');
15-
var p = new Parallel([1, 2, 3]);
14+
var Thread = require('../lib/thread.js');
15+
var p = new Thread([1, 2, 3]);
1616
expect(p.map).toEqual(jasmine.any(Function));
1717
});
1818

1919
it('should execute a .then function without an operation immediately', function () {
20-
var Parallel = require('../lib/thread.js');
21-
var p = new Parallel([1, 2, 3]);
20+
var Thread = require('../lib/thread.js');
21+
var p = new Thread([1, 2, 3]);
2222
expect(p.then).toEqual(jasmine.any(Function));
2323

2424
var done = false;
@@ -33,8 +33,8 @@
3333
});
3434

3535
it('should execute .spawn() correctly', function () {
36-
var Parallel = require('../lib/thread.js');
37-
var p = new Parallel([1, 2, 3]);
36+
var Thread = require('../lib/thread.js');
37+
var p = new Thread([1, 2, 3]);
3838

3939
var done = false;
4040
var result = null;
@@ -58,8 +58,8 @@
5858
});
5959

6060
it('should .map() correctly', function () {
61-
var Parallel = require('../lib/thread.js');
62-
var p = new Parallel([1, 2, 3]);
61+
var Thread = require('../lib/thread.js');
62+
var p = new Thread([1, 2, 3]);
6363

6464
var done = false;
6565
var result = null;
@@ -83,8 +83,8 @@
8383
});
8484

8585
it('should queue map work correctly', function () {
86-
var Parallel = require('../lib/thread.js');
87-
var p = new Parallel([1, 2, 3], {maxWorkers: 2});
86+
var Thread = require('../lib/thread.js');
87+
var p = new Thread([1, 2, 3], {maxWorkers: 2});
8888

8989
var done = false;
9090
var result = null;
@@ -108,8 +108,8 @@
108108
});
109109

110110
it('should chain .map() correctly', function () {
111-
var Parallel = require('../lib/thread.js');
112-
var p = new Parallel([1, 2, 3]);
111+
var Thread = require('../lib/thread.js');
112+
var p = new Thread([1, 2, 3]);
113113

114114
var done = false;
115115
var result = null;
@@ -135,8 +135,8 @@
135135
});
136136

137137
it('should mix .spawn and .map() correctly', function () {
138-
var Parallel = require('../lib/thread.js');
139-
var p = new Parallel([1, 2, 3]);
138+
var Thread = require('../lib/thread.js');
139+
var p = new Thread([1, 2, 3]);
140140

141141
var done = false;
142142
var result = null;
@@ -166,8 +166,8 @@
166166
});
167167

168168
it('should execute .reduce() correctly', function () {
169-
var Parallel = require('../lib/thread.js');
170-
var p = new Parallel([1, 2, 3]);
169+
var Thread = require('../lib/thread.js');
170+
var p = new Thread([1, 2, 3]);
171171
var done = false;
172172
var result = null;
173173

@@ -190,8 +190,8 @@
190190
});
191191

192192
it('should process data returned from .then()', function () {
193-
var Parallel = require('../lib/thread.js');
194-
var p = new Parallel([1, 2, 3]);
193+
var Thread = require('../lib/thread.js');
194+
var p = new Thread([1, 2, 3]);
195195

196196
var done = false;
197197
var result = null;

test/performance.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
return i;
1010
};
1111

12-
var Parallel = require('../lib/thread.js');
13-
var p = new Parallel([1000, 2000, 3000]);
14-
var p2 = new Parallel([1000, 2000, 3000]);
12+
var Thread = require('../lib/thread.js');
13+
var p = new Thread([1000, 2000, 3000]);
14+
var p2 = new Thread([1000, 2000, 3000]);
1515

1616
var start = Date.now();
1717
var start2 = Date.now();

0 commit comments

Comments
 (0)