Skip to content

Commit 037ef83

Browse files
author
Jan Kurella
committed
eliminate rare chance of race condition
One could loose the response of the spawned process due to too quick response message. So add lintener first, then call parallel process.
1 parent 995ef30 commit 037ef83

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/thread.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@
9595
this.operation.then(function () {
9696
var wrk = new Worker(that.options.path);
9797
wrk.postMessage(Thread.getWorkerSource(cb));
98-
wrk.postMessage(that.data);
9998
wrk.onmessage = function (msg) {
10099
wrk.terminate();
101100
that.data = msg.data;
102101
newOp.resolve(null, that.data);
103102
};
103+
wrk.postMessage(that.data);
104104
});
105105
this.operation = newOp;
106106
return this;
@@ -110,12 +110,12 @@
110110
var that = this;
111111
var wrk = new Worker(that.options.path);
112112
wrk.postMessage(Thread.getWorkerSource(cb));
113-
wrk.postMessage(that.data[i]);
114113
wrk.onmessage = function (msg) {
115114
wrk.terminate();
116115
that.data[i] = msg.data;
117116
done();
118117
};
118+
wrk.postMessage(that.data[i]);
119119
};
120120

121121
Thread.prototype.map = function (cb) {
@@ -148,12 +148,12 @@
148148
var that = this;
149149
var wrk = new Worker(that.options.path);
150150
wrk.postMessage(Thread.getWorkerSource(cb));
151-
wrk.postMessage(data);
152151
wrk.onmessage = function (msg) {
153152
wrk.terminate();
154153
that.data[that.data.length] = msg.data;
155154
done();
156155
};
156+
wrk.postMessage(data);
157157
};
158158

159159
Thread.prototype.reduce = function (cb) {

0 commit comments

Comments
 (0)