Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Feature/add workerize utility #2617

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

akinsho
Copy link
Member

@akinsho akinsho commented Oct 6, 2018

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
Copy link

codecov bot commented Oct 6, 2018

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.

@bryphe
Copy link
Member

bryphe commented Oct 8, 2018

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 😄 )

return webWorker.postMessage(result)
}

// courtesy of this gem -
Copy link
Member

Choose a reason for hiding this comment

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

Nice find!

@akinsho
Copy link
Member Author

akinsho commented Oct 13, 2018

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants