W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2018

Re: web Worker API suggestion

From: Patrick Kettner <Patrick.Kettner@microsoft.com>
Date: Sun, 13 May 2018 20:07:05 +0000
To: Andre Venancio <info@andrevenancio.com>, "public-webapps@w3.org" <public-webapps@w3.org>
Message-ID: <SN6PR00MB0384CA62C558B647BAD39D4FEE9D0@SN6PR00MB0384.namprd00.prod.outlook.com>
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

________________________________
From: Andre Venancio <info@andrevenancio.com>
Sent: Friday, May 11, 2018 9:25 AM
To: public-webapps@w3.org
Subject: web Worker API suggestion

Hi,
Not sure this is the best email to contact you guys regarding an API suggestion, but here it goes:


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?

From: current Worker API:

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
Received on Sunday, 13 May 2018 20:07:40 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:15:14 UTC