[whatwg] MessagePorts and message delivery ordering

On Thu, 6 Aug 2009, Drew Wilson wrote:
>
> I was writing some unit tests for SharedWorkers, and I saw some behavior
> that seems to be spec compliant, but which was counter-intuitive from a
> developer standpoint.
> Let's say that you have two message ports - some other window or a shared
> worker owns the other end of those ports.
> 
> You then do this:
> 
> port1.postMessage("foo");
> port2.postMessage("bar");
> 
> At the other end, the order of the delivery of these messages is entirely
> arbitrary (could be "foo"->"bar", or "bar"->"foo") even though those ports
> share the same owner. This is because each port is an individual task
> source, and ordering within a given task source is guaranteed by the spec,
> but ordering across task sources is intentionally not guaranteed (this
> allows UAs to prioritize task sources).

Woo, at least one person understands what's going on with the event loop 
design!


> Anyhow, just thought I'd point it out, and make sure there isn't 
> something in the spec that I missed that should affect delivery ordering 
> in this case.

I'm pretty sure your interpretation is correct. I'm not really sure 
whether to consider it a problem or not. It's a problem only if both ports 
are owned by the same owner on each end (i.e. port1 and port2 are owned by 
the same owner, obviously, but also port1' and port2' are owned by the 
same owner, though maybe a different owner than port1 and port2).

I don't really see any way around it. We can't really make the task source 
for ports be dependent on who the other end's owner is, because that might 
change asynchronously without the other owner knowing much about it.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Thursday, 6 August 2009 14:43:43 UTC