Re: Sync API for workers

Let me introduce the first sketch of a variant. The general idea is to
add a |postSyncMessage|

We extend DedicatedWorkerGlobalScope and MessageEvent as follows:

interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
  void postMessage(any message, optional sequence<Transferable> transfer);
  any postSyncMessage(any message, optional sequence<Transferable>
transfer);
};

interface SyncMessageEvent : MessageEvent {
  void reply(optional any message, optional sequence<Transferable>
transfer);
};

The behavior of |postSyncMessage| is the following:
1. the sender worker sleeps and does not handle any |postMessage|
messages until it is awakened;
2. instead of the usual |MessageEvent|, the target's |onmessage|
receives as argument a |SyncMessageEvent| (call it |s|);
3. if |s.reply(x)| is called, the sender's |postSyncMessage| method
returns a copy of |x|, obtained with the usual algorithm;
5. if |s.reply()| has not called by the time the worker is either
garbage-collected or |terminate()| is called on its |MessagePort|, the
worker is killed as usual.

I have not attempted to detail the inner workings of the underlying
MessagePort, but I suspect that this is close to Jonas Sicking's proposal.

Cheers,
 David

Received on Monday, 14 October 2013 09:33:40 UTC