oni icon indicating copy to clipboard operation
oni copied to clipboard

Feature/add workerize utility

Open akinsho opened this issue 6 years ago • 3 comments

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

akinsho avatar Oct 06 '18 11:10 akinsho

Codecov Report

Merging #2617 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@          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.

codecov[bot] avatar Oct 06 '18 13:10 codecov[bot]

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 avatar Oct 08 '18 15:10 bryphe

@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

akinsho avatar Oct 13 '18 14:10 akinsho