Skip to content

Instantly share code, notes, and snippets.

@chrispsn
Last active March 24, 2018 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrispsn/f90a7f347df74760d43b5d5a8d581972 to your computer and use it in GitHub Desktop.
Save chrispsn/f90a7f347df74760d43b5d5a8d581972 to your computer and use it in GitHub Desktop.
Playing with Web Workers so we can get rid of sheet references in Mesh while not polluting the window scope.
var myWorker = new Worker('worker.js');
myWorker.onmessage = (e) => console.log(e.data);
myWorker.postMessage("Hello!");
importScripts("libR.min.js");
let numbers = [1, 2, 3];
self.cool = () => hey
+ " I am a function referencing a variable before it was defined!"
+ "\nLook, I can import and call some R functions from a library! Sum of " + numbers + " is " + libR.R.sum(numbers);
self.hey = " This is a worker!";
onmessage = function(e) {
postMessage(e.data + cool());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment