In letterscore/createWords I realized that the text input was being laggy: this is because javascript is single threaded and must wait while the synchronous message was being sent.
Here is my solution:
The client and server both start out with
communications_number = 0
The client sends the request asynchronously to the server, along with its current communications_number
When the server receives a request, it checks the communications number.
If this number is equal to the current number, then the server increments its communications_number.
Otherwise, it does not.
Then the server sends the response back with its current communication_number.
When the client gets the server's communication_number, it checks whether or not this number is greater than its current communication_number.
If it isn't greater, then this is an old packet and we skipped a couple of numbers; we have already processed a newer packet!
If it is greater, then its a new packet, and so we set our communication_number = the server's communication_number.
In this way the client can arrange the old and new data appropriately; it is easy to see how when you know the ordering of things, quite apart from when you actual received them, that you can reconstruct them into an ordered set.
Or in other words, we can have sequential behaviour without having to wait for sequential computations to finish!
I think I might wrap this behaviour up in a javascript prototype object!
10 February 2010
Subscribe to:
Post Comments (Atom)
hmmm chinese porn spam... interesting
ReplyDelete