On 14 Jan, 09:30 am, johnaherne@rocs.co.uk wrote:
I have been looking at JPCalderones example of using web.request with JSON which seems much like what I want.
One thing I am not clear about is if I get a lot of queries coming in more or less simultaneously and I am using cooperate to allow other functions to run, will I need to guard against my data in a list being overwritten by subsequent requests.
The way I see it the functions to read data and and store it in my list are in danger of impacting each other.
The response is being built cooperatively bit by bit to permit other functions to run so it could happen that the next request overwrites my list where the database query is being stored.
Any time you have shared mutable state, you have this possibility. You do need to take measures to avoid making one request destroy the state associated with another request.
If this is a danger, then I need to prevent this, which seems to imply that I will need to block each request and not service another request until the previous one has completed.
Serializing (ie, not processing a second request until the first is completed) processing is one way to accomplish this. However, another way to accomplish it is to not have shared mutable state. A quick skim of your code suggests you don't actually have much, if any, shared mutable state. The list holding your database results is a local variable, and each request builds its own (as far as I can tell). There is no danger of different requests interfering with each other in this case. Jean-Paul