Andre Venancio
2018-05-14 17:13:42 UTC
Hi Patrick.
Been having a look at that option too, however a linter wouldnt easily
parse that in order to validate my javascript.. I do understand your point,
however makes me feel dirty having to include a task for copying static
file around from my SRC to my DIST folders. would be easier if there was a
way of accessing another memory thread without having to handle this
external file requirement.
Been having a look at that option too, however a linter wouldnt easily
parse that in order to validate my javascript.. I do understand your point,
however makes me feel dirty having to include a task for copying static
file around from my SRC to my DIST folders. would be easier if there was a
way of accessing another memory thread without having to handle this
external file requirement.
Hey Andre!
The issue with this is that it would not be obvious that you are unable to
pass objects from the current scope into the worker (which would break the
entire purpose of having a fast codepath in another thread). You *can* construct
one from a string, however. You just need to wrap it up like a file
<https://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string>
cheers
patrick
------------------------------
*Sent:* Friday, May 11, 2018 9:25 AM
*Subject:* web Worker API suggestion
Hi,
Not sure this is the best email to contact you guys regarding an API
I've been thinking about this for a while now, and I think it would be
beneficial to update the Worker api to allow you to pass a IIFI function
instead of a external file?
const worker = new Worker('lame.js');
worker.onmessage = (e) => {
console.log(e);
};
// lame.js
this.addEventListener('message', (e) => {
this.postMessage({ message: 'hello back' });
});
to
const worker = new Worker(() => {
this.addEventListener('message', (e) => {
this.postMessage({ message: 'hello back' });
});
});
worker.onmessage = (e) => {
console.log(e);
};
Wouldn't this be better?
Thanks
Andre
The issue with this is that it would not be obvious that you are unable to
pass objects from the current scope into the worker (which would break the
entire purpose of having a fast codepath in another thread). You *can* construct
one from a string, however. You just need to wrap it up like a file
<https://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string>
cheers
patrick
------------------------------
*Sent:* Friday, May 11, 2018 9:25 AM
*Subject:* web Worker API suggestion
Hi,
Not sure this is the best email to contact you guys regarding an API
I've been thinking about this for a while now, and I think it would be
beneficial to update the Worker api to allow you to pass a IIFI function
instead of a external file?
const worker = new Worker('lame.js');
worker.onmessage = (e) => {
console.log(e);
};
// lame.js
this.addEventListener('message', (e) => {
this.postMessage({ message: 'hello back' });
});
to
const worker = new Worker(() => {
this.addEventListener('message', (e) => {
this.postMessage({ message: 'hello back' });
});
});
worker.onmessage = (e) => {
console.log(e);
};
Wouldn't this be better?
Thanks
Andre