oni
oni copied to clipboard
Feature/add workerize utility
cc @bryphe
I've been experimenting with worker support still, and discovered a very minimal way to execute a pure function in a separate thread, this is similar to the greenlet
library just even smaller.
It takes a function, and its arguments and runs the code in a separate thread, unfortunately I can't find any expensive pure functions to use it on.
I'm working on the syntaxHighlightingPeriodicJob on another branch, unfortunately it has quite a few external dependencies, currently blocked by the fact that vscode-textmate
references the process variable which is undefined in the worker thread so causes errors
Codecov Report
Merging #2617 into master will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #2617 +/- ##
======================================
Coverage 45.3% 45.3%
======================================
Files 361 361
Lines 14571 14571
Branches 1912 1912
======================================
Hits 6601 6601
Misses 7746 7746
Partials 224 224
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 b31243d...d969d5e. Read the comment docs.
Thanks for introducing this, @Akin909 !
I'm working on the syntaxHighlightingPeriodicJob on another branch, unfortunately it has quite a few external dependencies, currently blocked by the fact that vscode-textmate references the process variable which is undefined in the worker thread so causes errors
That's a bummer. I wonder why they need process? Potentially, we could fork vscode-textmate
and pass in whatever context it needs as part of the our 'pure function' we run in the worker, as opposed to it needing to query the process
global.
Would it be possible to add a quick test case demonstrating its usage?
Even just a simple test case like:
let result = await workerize(({a, b}) => a + b, {a: 2, b: 3}); assert.strictEqual(result, 5);
(Essentially its documentation on how this can be used 😄 )
@bryphe sure will add a simple test to this PR.
Re. vscode-textmate and the use of process they use it to have access to env variables for debugging as well as for one particular script that can be run from the commandline. I had the same thought re. forking the library was trying to decide between that and waiting to see if the issue that relates to that for the loader moves forward at all and we might be able to bypass the need, although not sure as the package seems intended for node as opposed to the browser