Standardize ES Worker

Boris Zbarsky bzbarsky at mit.edu
Thu Oct 27 13:57:15 UTC 2016


On 10/27/16 9:48 AM, Michał Wadas wrote:
> Currently we put emphasis on request-response model - we request
> something from function (returning Promise/taking callback) and we wait
> for single return value. Workers are different beasts - they can emit
> messages on their own and don't have to emit ANY messages on completion.

Right.  The point of workers in the web platform is to do computation in 
a separate context.  The computation need not be communicated back to 
the spawning page, because workers can do their own I/O.

> // main.js
> const worker = new Worker('worker.js');
> worker.request('ajaxCall', {url: 'example.com <http://example.com>'});
> // return Promise resolving to Response object
> worker.request('undefinedMethod'); // return rejected Promise
>
> // worker.js
>
> self.on('ajaxCall', (data)=>{ return Promise.resolve(new Response); });

Workers in the web platform have a shared-nothing model.  The above 
example seems to assume that the Response and the Promise are either 
shared across the main script and the worker or auto-cloned at the 
boundary, right?

-Boris


More information about the es-discuss mailing list