Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to inject functions into the workers #1235

Closed
wants to merge 22 commits into from

Conversation

DeMoorJasper
Copy link
Member

@DeMoorJasper DeMoorJasper commented Apr 23, 2018

Changes the way workers are used from registering functions/file to just requesting a function with it's path. Using mkHandle

Example:

let something = workerfarm.mkhandle(require.resolve('./worker.js'), 'doSomething');
let result = await something(...args);

@codecov-io
Copy link

codecov-io commented Apr 23, 2018

Codecov Report

Merging #1235 into master will increase coverage by 2.75%.
The diff coverage is 65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1235      +/-   ##
==========================================
+ Coverage   85.86%   88.61%   +2.75%     
==========================================
  Files          77       78       +1     
  Lines        4307     4384      +77     
==========================================
+ Hits         3698     3885     +187     
+ Misses        609      499     -110
Impacted Files Coverage Δ
src/workerfarm/Worker.js 68.42% <0%> (-0.33%) ⬇️
src/workerfarm/child.js 95.12% <100%> (+0.03%) ⬆️
src/workerfarm/childBootstrap.js 100% <100%> (ø)
src/workerfarm/WorkerFarm.js 46.66% <42.85%> (-2.69%) ⬇️
src/assets/VueAsset.js 80% <0%> (-6.67%) ⬇️
src/visitors/dependencies.js 89.13% <0%> (-5.44%) ⬇️
src/assets/GLSLAsset.js 93.1% <0%> (-3.2%) ⬇️
src/transforms/uglify.js 71.73% <0%> (-2.18%) ⬇️
src/utils/serializeObject.js 88.23% <0%> (-1.77%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d984a5...0bf45af. Read the comment docs.

@devongovett
Copy link
Member

Most plugins are asset types and already run in workers right?

this.localWorker = require('./childBootstrap');
this.registerWorkerFunctions(this.options.workerPath || '../worker', [
'run',
'init'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could autodetect these instead of needing to list them? Basically Object.keys(require(workerPath))?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it, but think it'll be more precise if it has to be defined when being called.
For example if a worker has more than just the worker functions as exports we don't add a handler for all of them.
If we document this eventually it should be fine to use export keys I guess.

@DeMoorJasper
Copy link
Member Author

@devongovett Yes that's true, the typescript one utilises workers for speeding up error handling. It would be faster and probably better if the plugin wouldn't have to start and handle it's own workers.
Not sure how this exactly works I haven't dug into the code of parcel-plugin-ts

@devongovett
Copy link
Member

Also seems like this would potentially lead to different modules overwriting each other if they had the same function names. What if instead we just made the processRequest of the WorkerFarm work on both ends. So when you made a call to the worker farm, you'd specify both a module path and a function name rather than only having one module loaded into the children. This would work exactly the same way as when we call from children to parents. What do you think?

@DeMoorJasper
Copy link
Member Author

@devongovett If this doesn't impact performance or code readability it's probably a great idea. Would definitely solve the problem of 2 plugins possibly having a naming conflict

@DeMoorJasper DeMoorJasper deleted the workerfarm-plugin-extension branch May 27, 2018 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants