-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom workerfarm, BI-Directional IPC (#1105)
- Loading branch information
1 parent
25a054f
commit 69625e0
Showing
20 changed files
with
920 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
require('v8-compile-cache'); | ||
const Pipeline = require('./Pipeline'); | ||
const child = require('./workerfarm/child'); | ||
const WorkerFarm = require('./workerfarm/WorkerFarm'); | ||
|
||
let pipeline; | ||
|
||
exports.init = function(options, callback) { | ||
function init(options, isLocal = false) { | ||
pipeline = new Pipeline(options || {}); | ||
Object.assign(process.env, options.env || {}); | ||
process.env.HMR_PORT = options.hmrPort; | ||
process.env.HMR_HOSTNAME = options.hmrHostname; | ||
callback(); | ||
}; | ||
if (isLocal) { | ||
process.env.WORKER_TYPE = 'parcel-worker'; | ||
} | ||
} | ||
|
||
exports.run = async function(path, pkg, options, isWarmUp, callback) { | ||
async function run(path, pkg, options, isWarmUp) { | ||
try { | ||
options.isWarmUp = isWarmUp; | ||
var result = await pipeline.process(path, pkg, options); | ||
|
||
callback(null, result); | ||
} catch (err) { | ||
let returned = err; | ||
returned.fileName = path; | ||
callback(returned); | ||
return await pipeline.process(path, pkg, options); | ||
} catch (e) { | ||
e.fileName = path; | ||
throw e; | ||
} | ||
}; | ||
} | ||
|
||
process.on('unhandledRejection', function(err) { | ||
// ERR_IPC_CHANNEL_CLOSED happens when the worker is killed before it finishes processing | ||
if (err.code !== 'ERR_IPC_CHANNEL_CLOSED') { | ||
console.error('Unhandled promise rejection:', err.stack); | ||
// request.location is a module path relative to src or lib | ||
async function addCall(request, awaitResponse = true) { | ||
if (process.send && process.env.WORKER_TYPE === 'parcel-worker') { | ||
return child.addCall(request, awaitResponse); | ||
} else { | ||
return WorkerFarm.getShared().processRequest(request); | ||
} | ||
}); | ||
} | ||
|
||
exports.init = init; | ||
exports.run = run; | ||
exports.addCall = addCall; |
Oops, something went wrong.