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

[whatwg] workers

From: Aaron Boodman <aa@google.com>
Date: Mon, 15 Sep 2008 13:56:02 +0100
Message-ID: <278fd46c0809150556w63decachae43591b8f83c8bf@mail.gmail.com>
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 05:56:02 UTC

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