[whatwg] workers
Aaron Boodman
aa at google.com
Mon Sep 15 05:56:02 PDT 2008
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
More information about the whatwg
mailing list