Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
send(data: WorkerMessage) {
if (!this.processQueue) {
this.sendQueue.push(data);
return;
}
let result = this.child.send(serialize(data).toString('base64'), error => {
if (error && error instanceof Error) {
// Ignore this, the workerfarm handles child errors
return;
}
this.processQueue = true;
if (this.sendQueue.length > 0) {
let queueCopy = this.sendQueue.slice(0);
this.sendQueue = [];
queueCopy.forEach(entry => this.send(entry));
}
});
if (!result || /^win/.test(process.platform)) {
// Queue is handling too much messages throttle it
callMaster: async (
request: CallRequest,
awaitResponse: ?boolean = true,
): Promise => {
// $FlowFixMe
let result = await this.processRequest({
...request,
awaitResponse,
});
return deserialize(serialize(result));
},
createReverseHandle: (fn: HandleFunction): Handle =>
send(data: WorkerMessage) {
let processSend = nullthrows(process.send).bind(process);
processSend(serialize(data).toString('base64'), err => {
if (err && err instanceof Error) {
if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
// IPC connection closed
// no need to keep the worker running if it can't send or receive data
return this.stop();
}
}
});
}
async set(key: string, value: mixed) {
try {
let blobPath = this._getCachePath(key);
let data = serialize(value);
await this.fs.writeFile(blobPath, data);
return key;
} catch (err) {
logger.error(err, '@parcel/cache');
}
}
}
async set(key: string, value: mixed) {
try {
let blobPath = this._getCachePath(key);
let data = serialize(value);
await this.fs.writeFile(blobPath, data);
return key;
} catch (err) {
logger.error(`Error writing to cache: ${err.message}`);
}
}
}
async set(key: string, value: mixed) {
await this.request(this._getCachePath(key), {
method: 'put',
body: serialize(value),
headers: {
'content-type': 'application/octet-stream'
}
});
return key;
}
}