W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2008

[whatwg] workers

From: Chris Prince <cprince@google.com>
Date: Mon, 15 Sep 2008 07:52:12 -0700
Message-ID: <cd580da00809150752i3ea9c3d6t40a1ad0bbb71e3f4@mail.gmail.com>
I like this a lot.  +1 to making connect() always explicit.  Implicit
creation of ports led to many rough edges.

I think your proposal nearly works for window.postMessage() too.  If
you move 'onconnect' and 'connect()' into a MessageReceiver interface
[better name TBD], and make Worker and Window both inherit from
MessageReceiver, do you end up with a unified messaging model?


On Mon, Sep 15, 2008 at 5:56 AM, Aaron Boodman <aa at google.com> wrote:
> Thinking about this some more, having the "port" convenience
> properties gets confusing when there are multiple clients sending
> messages, and doesn't make a whole lot of sense with shared workers.
>
> I think we should just get rid of these. It only adds one line of code
> to the simple case. Also, I forgot 'onerror' in my last IDL proposal.
> So here's an update:
>
> OUTSIDE
>
> interface MessagePort {
>  EventListener onmessage;
>  EventListener onclose;
>  void sendMessage(String message);
> }
>
> interface Worker {
>  EventListener onload;  // informative only, you can sendMessage
> before this happens
>  EventListener onerror;  // only load errors, not script errors at runtime
>  Port connect();
> };
>
> interface DedicatedWorker : Worker {
>  void close();
> };
>
> INSIDE
>
> interface WorkerContext {
>  EventListener onclose;
>  EventListener onmessage;  // convenience -- receives all messages
> sent to ports in this worker
>  EventListener onconnect;  // fired each time connect() is called on
> a corresponding Worker object
>
>  readonly String name;
>  void close();
>
>  // + all the utils stuffs
> };
>
> EXAMPLE USAGE
>
> var worker = new Worker("foo.js");
> var port = worker.connect();
> port.onmessage = function(e) {
>  alert("worker says: " + e.message);
> }
> port.sendMessage("hi!");
>
> // foo.js
> self.onconnect = function(e) {
>  e.port.onmessage = function() {
>    e.port.sendMessage("bye");
>  }
> }
>
> // foo.js (alternate implementation)
> self.onmessage = function(e) {
>  e.port.sendMessage("bye");
> }
>
> - a
>
Received on Monday, 15 September 2008 07:52:12 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:05 UTC