[whatwg] reply() extension to postMessage()

On Thu, Feb 14, 2008 at 8:18 AM, Anne van Kesteren <annevk at opera.com> wrote:
>    e.reply(message)
>
>  is equivalent to
>
>    e.source.postMessage(message, e.origin)

If we're going to add reply, I would like to easily be able to get
replies to a specific message. So extend postMessage to accept a
callback, and then either have reply() call this callback. Like this:

// sender:
someWindow.postMessage("hello!", function(response) {
  alert("got response: " + response);
});

// receiver
window.addEventListener("message", function(e) {
  alert("got message: " + e.message);
  e.reply("good day");
});

This solves a real problem that we have experienced with workers
(which have the same messaging style interface as post-message). Which
is that you have to send message IDs in all your messages and stitch
them back together manually.

Sorry again if I got identifier names wrong in this message, I have
not been keeping up with the changes to postMessage.

- a

- a

Received on Thursday, 14 February 2008 08:30:15 UTC