13.5. Tracing the entire process from client to PDR and back
-
The client initiates the process by calling one of the functions exposed by PerspectivesProxy.
-
PerspectivesProxy delegates the request to its Channel, including the callback function provided by the client or a callback function it has constructed itself to fulfill the promise returned by PerspectivesProxy.
-
The Channel send function constructs a Correlation Identifier, stores the callback and sends a serialised version of the request, including the Channel ID and the Correlation Identifier, through the Messaging API.
-
The SharedWorker receives that serialised request. It creates its own callback function that encapsulates both the ChannelID and the Correlation Identifier. It calls the
emit
function provided by the PDR, sending its self-constructed callback function along. -
The PDR interprets the serialised request and constructs an answer. It calls the callback function, which in turn serialises the answer and sends it through the Messaging API (using the Channel ID in the response to select the right MessagePort).
-
The SharedWorkerChannel (on a client side), listening on its MessagePort, receives the result. Using the Correlation Identifier included in the result, it selects the original callback function and applies it to the result. The callback function fulfills a promise or does something to React State, updating the screen.