workers: misc fixes.
This commit is contained in:
parent
4ebe557807
commit
886008a182
@ -83,13 +83,14 @@ Master.prototype._initWebWorkers = function _initWebWorkers() {
|
||||
|
||||
global.onmessage = (event) => {
|
||||
let data;
|
||||
if (typeof event.data !== 'string') {
|
||||
if (typeof event.data === 'string') {
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
assert(data.length === event.data.length / 2);
|
||||
} else {
|
||||
assert(event.data && typeof event.data === 'object');
|
||||
assert(event.data.data);
|
||||
assert(event.data.data && typeof event.data.data.length === 'number');
|
||||
data = event.data.data;
|
||||
data.__proto__ = Buffer.prototype;
|
||||
} else {
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
}
|
||||
this.emit('data', data);
|
||||
};
|
||||
@ -112,7 +113,7 @@ Master.prototype._initChildProcess = function _initChildProcess() {
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
this.send(new packets.ErrorPacket(err));
|
||||
setTimeout(() => process.exit(1), 500);
|
||||
setTimeout(() => process.exit(1), 1000);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ WorkerPool.prototype.close = async function close() {
|
||||
*/
|
||||
|
||||
WorkerPool.prototype.spawn = function spawn(id) {
|
||||
let child = new Worker(id);
|
||||
let child = new Worker(id, this.masterURL);
|
||||
|
||||
child.on('error', (err) => {
|
||||
this.emit('error', err, child);
|
||||
@ -416,24 +416,25 @@ WorkerPool.prototype.scrypt = async function scrypt(passwd, salt, N, r, p, len)
|
||||
* Represents a worker.
|
||||
* @alias module:workers.Worker
|
||||
* @constructor
|
||||
* @param {Number?} id
|
||||
* @param {Number} id
|
||||
* @param {String} masterURL
|
||||
*/
|
||||
|
||||
function Worker(id) {
|
||||
function Worker(id, masterURL) {
|
||||
if (!(this instanceof Worker))
|
||||
return new Worker(id);
|
||||
return new Worker(id, masterURL);
|
||||
|
||||
EventEmitter.call(this);
|
||||
|
||||
this.framer = new Framer();
|
||||
this.parser = new Parser();
|
||||
|
||||
this.id = id != null ? id : -1;
|
||||
this.id = id;
|
||||
this.child = null;
|
||||
this.pending = new Map();
|
||||
|
||||
this.env = {
|
||||
BCOIN_MASTER_URL: this.masterURL,
|
||||
BCOIN_MASTER_URL: masterURL,
|
||||
BCOIN_WORKER_NETWORK: Network.type,
|
||||
BCOIN_WORKER_ISTTY: process.stdout
|
||||
? (process.stdout.isTTY ? '1' : '0')
|
||||
@ -491,13 +492,14 @@ Worker.prototype._initWebWorkers = function _initWebWorkers() {
|
||||
|
||||
this.child.onmessage = (event) => {
|
||||
let data;
|
||||
if (typeof event.data !== 'string') {
|
||||
if (typeof event.data === 'string') {
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
assert(data.length === event.data.length / 2);
|
||||
} else {
|
||||
assert(event.data && typeof event.data === 'object');
|
||||
assert(event.data.data);
|
||||
assert(event.data.data && typeof event.data.data.length === 'number');
|
||||
data = event.data.data;
|
||||
data.__proto__ = Buffer.prototype;
|
||||
} else {
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
}
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user