Skip to content

Commit 53fbd09

Browse files
committed
Changes readScript() to send async requests
1 parent 0369cff commit 53fbd09

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

glminer.js

+22-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function meinWebGLStart(threads) {
3232

3333
var names = [ "webgl", "experimental-webgl", "moz-webgl", "webkit-3d" ];
3434
for (var i=0; i<names.length; i++) {
35-
try {
35+
try {
3636
gl = canvas.getContext(names[i]);
3737
if (gl) { break; }
3838
} catch (e) { }
@@ -128,22 +128,29 @@ function meinWebGLStart(threads) {
128128
gl.uniform2fv(kLoc, k);
129129
}
130130

131-
function readScript(n) {
131+
function readScript(n, callback) {
132132
var xhr = new XMLHttpRequest();
133-
xhr.open("GET", n, false);
133+
xhr.open("GET", n, true);
134134
xhr.send(null);
135-
var x = xhr.responseText;
136-
return x;
135+
136+
xhr.onload = function () {
137+
callback(xhr.responseText);
138+
}
137139
};
138140

139141
function onl() {
140-
vShaderQuellcode = readScript('shader-vs.js');
141-
fShaderQuellcode = readScript('shader-fs.js');
142+
readScript('shader-vs.js', function (data) {
143+
vShaderQuellcode = data;
144+
});
145+
146+
readScript('shader-fs.js', function (data) {
147+
fShaderQuellcode = data;
148+
});
142149
};
143150

144151
function glminer(job, callback) {
145152
var run = true;
146-
153+
147154
var next_run = function(job, callback) {
148155
var nonces_per_pixel = 1;
149156
var t = job.t === undefined ? 0 : job.t;
@@ -156,7 +163,7 @@ function glminer(job, callback) {
156163

157164
var submit_nonce = function() {
158165
n = derMiner.Util.to_uint16_array(job.nonce);
159-
166+
160167
job.data[6] = n[0];
161168
job.data[7] = n[1];
162169

@@ -165,9 +172,9 @@ function glminer(job, callback) {
165172
r.push(job.half[j]);
166173
for (var j = 0; j < job.data.length; j++)
167174
r.push(job.data[j]);
168-
175+
169176
var ret = derMiner.Util.toPoolString(r, true);
170-
177+
171178
job.golden_ticket = ret;
172179
callback(job);
173180
}
@@ -176,7 +183,7 @@ function glminer(job, callback) {
176183
n = derMiner.Util.to_uint16_array(nonce);
177184
gl.uniform2fv(nonceLoc, n);
178185
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
179-
186+
180187
if (debug) console.log("w:" + width + " h:" + height);
181188

182189
gl.readPixels(x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
@@ -214,7 +221,7 @@ function glminer(job, callback) {
214221
}
215222
}
216223
}
217-
224+
218225
job.golden_ticket = null;
219226
}
220227
}
@@ -234,7 +241,7 @@ function glminer(job, callback) {
234241
callback(job);
235242
TotalHashes = 0;
236243
}
237-
244+
238245
if (useTimeout && ++curCnt > maxCnt) {
239246
curCnt = 0;
240247
job.nonce = nonce;
@@ -274,7 +281,7 @@ function glminer(job, callback) {
274281
var is_golden_hash = function(hash, target) {
275282
var u1 = derMiner.Util.ToUInt32(hash);
276283
var u2 = derMiner.Util.ToUInt32(target[6]);
277-
284+
278285
console.log("worker: checking " + u1 + " <= " + u2);
279286
return (u1 <= u2);
280287
}

0 commit comments

Comments
 (0)