Skip to content

Commit 055f5ef

Browse files
committed
Rename thread.js back to parallel.js
1 parent 1d8104f commit 055f5ef

File tree

5 files changed

+53
-53
lines changed

5 files changed

+53
-53
lines changed

lib/thread.js renamed to lib/parallel.js

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

77-
function Thread(data, options) {
77+
function Parallel(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-
Thread.getWorkerSource = function (cb) {
84+
Parallel.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-
Thread.prototype._spawnWorker = function (cb) {
92+
Parallel.prototype._spawnWorker = function (cb) {
9393
var wrk;
9494
if (isNode) {
9595
wrk = new Worker(this.options.path);
96-
wrk.postMessage(Thread.getWorkerSource(cb));
96+
wrk.postMessage(Parallel.getWorkerSource(cb));
9797
} else {
9898
try {
99-
var blob = new Blob([Thread.getWorkerSource(cb)], { type: 'text/javascript' });
99+
var blob = new Blob([Parallel.getWorkerSource(cb)], { type: 'text/javascript' });
100100
var url = URL.createObjectURL(blob);
101101

102102
wrk = new Worker(url);
@@ -113,7 +113,7 @@
113113
return wrk;
114114
};
115115

116-
Thread.prototype.spawn = function (cb) {
116+
Parallel.prototype.spawn = function (cb) {
117117
var that = this;
118118
var newOp = new Operation();
119119
this.operation.then(function () {
@@ -129,7 +129,7 @@
129129
return this;
130130
};
131131

132-
Thread.prototype._spawnMapWorker = function (i, cb, done) {
132+
Parallel.prototype._spawnMapWorker = function (i, cb, done) {
133133
var that = this;
134134
var wrk = that._spawnWorker(cb);
135135
wrk.onmessage = function (msg) {
@@ -140,7 +140,7 @@
140140
wrk.postMessage(that.data[i]);
141141
};
142142

143-
Thread.prototype.map = function (cb) {
143+
Parallel.prototype.map = function (cb) {
144144
if (!this.data.length) {
145145
return this.spawn(cb);
146146
}
@@ -166,7 +166,7 @@
166166
return this;
167167
};
168168

169-
Thread.prototype._spawnReduceWorker = function (data, cb, done) {
169+
Parallel.prototype._spawnReduceWorker = function (data, cb, done) {
170170
var that = this;
171171
var wrk = that._spawnWorker(cb);
172172
wrk.onmessage = function (msg) {
@@ -177,7 +177,7 @@
177177
wrk.postMessage(data);
178178
};
179179

180-
Thread.prototype.reduce = function (cb) {
180+
Parallel.prototype.reduce = function (cb) {
181181
if (!this.data.length) {
182182
throw new Error('Can\'t reduce non-array data');
183183
}
@@ -209,7 +209,7 @@
209209
return this;
210210
};
211211

212-
Thread.prototype.then = function (cb, errCb) {
212+
Parallel.prototype.then = function (cb, errCb) {
213213
var that = this;
214214
var newOp = new Operation();
215215
this.operation.then(function () {
@@ -224,8 +224,8 @@
224224
};
225225

226226
if (isNode) {
227-
module.exports = Thread;
227+
module.exports = Parallel;
228228
} else {
229-
self.Thread = Thread;
229+
self.Parallel = Parallel;
230230
}
231231
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"author": "Sebastian Mayr <sebmaster16@gmail.com>",
55
"description": "thread.js enables easy multi-thread processing in javascript",
6-
"main": "lib/thread.js",
6+
"main": "lib/parallel.js",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/Sebmaster/thread.js.git"

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 Thread = require('../lib/thread.js');
4-
expect(Thread).toEqual(jasmine.any(Function));
3+
var Parallel = require('../lib/parallel.js');
4+
expect(Parallel).toEqual(jasmine.any(Function));
55
});
66

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

1313
it('should define a .map(cb) function', function () {
14-
var Thread = require('../lib/thread.js');
15-
var p = new Thread([1, 2, 3]);
14+
var Parallel = require('../lib/parallel.js');
15+
var p = new Parallel([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 Thread = require('../lib/thread.js');
21-
var p = new Thread([1, 2, 3]);
20+
var Parallel = require('../lib/parallel.js');
21+
var p = new Parallel([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 Thread = require('../lib/thread.js');
37-
var p = new Thread([1, 2, 3]);
36+
var Parallel = require('../lib/parallel.js');
37+
var p = new Parallel([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 Thread = require('../lib/thread.js');
62-
var p = new Thread([1, 2, 3]);
61+
var Parallel = require('../lib/parallel.js');
62+
var p = new Parallel([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 Thread = require('../lib/thread.js');
87-
var p = new Thread([1, 2, 3], {maxWorkers: 2});
86+
var Parallel = require('../lib/parallel.js');
87+
var p = new Parallel([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 Thread = require('../lib/thread.js');
112-
var p = new Thread([1, 2, 3]);
111+
var Parallel = require('../lib/parallel.js');
112+
var p = new Parallel([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 Thread = require('../lib/thread.js');
139-
var p = new Thread([1, 2, 3]);
138+
var Parallel = require('../lib/parallel.js');
139+
var p = new Parallel([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 Thread = require('../lib/thread.js');
170-
var p = new Thread([1, 2, 3]);
169+
var Parallel = require('../lib/parallel.js');
170+
var p = new Parallel([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 Thread = require('../lib/thread.js');
194-
var p = new Thread([1, 2, 3]);
193+
var Parallel = require('../lib/parallel.js');
194+
var p = new Parallel([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
@@ -8,9 +8,9 @@
88
return i;
99
};
1010

11-
var Thread = require('../lib/thread.js');
12-
var p = new Thread([10000, 20000, 30000]);
13-
var p2 = new Thread([10000, 20000, 30000]);
11+
var Parallel = require('../lib/parallel.js');
12+
var p = new Parallel([10000, 20000, 30000]);
13+
var p2 = new Parallel([10000, 20000, 30000]);
1414

1515
var start;
1616
var time = null;

test/q-api.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
var Q = require('q');
66

77
it('should execute .spawn() correctly', function () {
8-
var Thread = require('../lib/thread.js');
9-
var p = new Thread([1, 2, 3]);
8+
var Parallel = require('../lib/parallel.js');
9+
var p = new Parallel([1, 2, 3]);
1010

1111
var done = false;
1212
var result = null;
@@ -30,8 +30,8 @@
3030
});
3131

3232
it('should .map() correctly', function () {
33-
var Thread = require('../lib/thread.js');
34-
var p = new Thread([1, 2, 3]);
33+
var Parallel = require('../lib/parallel.js');
34+
var p = new Parallel([1, 2, 3]);
3535

3636
var done = false;
3737
var result = null;
@@ -55,8 +55,8 @@
5555
});
5656

5757
it('should queue map work correctly', function () {
58-
var Thread = require('../lib/thread.js');
59-
var p = new Thread([1, 2, 3], { maxWorkers: 2 });
58+
var Parallel = require('../lib/parallel.js');
59+
var p = new Parallel([1, 2, 3], { maxWorkers: 2 });
6060

6161
var done = false;
6262
var result = null;
@@ -80,8 +80,8 @@
8080
});
8181

8282
it('should chain .map() correctly', function () {
83-
var Thread = require('../lib/thread.js');
84-
var p = new Thread([1, 2, 3]);
83+
var Parallel = require('../lib/parallel.js');
84+
var p = new Parallel([1, 2, 3]);
8585

8686
var done = false;
8787
var result = null;
@@ -109,8 +109,8 @@
109109
});
110110

111111
it('should mix .spawn and .map() correctly', function () {
112-
var Thread = require('../lib/thread.js');
113-
var p = new Thread([1, 2, 3]);
112+
var Parallel = require('../lib/parallel.js');
113+
var p = new Parallel([1, 2, 3]);
114114

115115
var done = false;
116116
var result = null;
@@ -142,8 +142,8 @@
142142
});
143143

144144
it('should execute .reduce() correctly', function () {
145-
var Thread = require('../lib/thread.js');
146-
var p = new Thread([1, 2, 3]);
145+
var Parallel = require('../lib/parallel.js');
146+
var p = new Parallel([1, 2, 3]);
147147
var done = false;
148148
var result = null;
149149

@@ -166,8 +166,8 @@
166166
});
167167

168168
it('should process data returned from .then()', function () {
169-
var Thread = require('../lib/thread.js');
170-
var p = new Thread([1, 2, 3]);
169+
var Parallel = require('../lib/parallel.js');
170+
var p = new Parallel([1, 2, 3]);
171171

172172
var done = false;
173173
var result = null;

0 commit comments

Comments
 (0)