On Tue, 2008-07-15 at 21:46 -0700, partner56290674 wrote:
> it's possible to possibly wait for the user to stop panning.
> Currently, when the pan ends, an onEnd event is fired, which then
> fires off the ajax. So what you're suggesting is that i queue the pan
> onEnd events?

I recently needed some queuing and handled it as:

1) Define var array e_pending to hold events in queue
2) Define var int e_concurrent to handle max events that could run at
once
3) Define var int e_running to say how many requests were running

As events come in I add them to e_pending array. When adding an event
here I also check if runQueueTimer is set and fire off a function called
runQueue() that processes the events in the e_pending array if it isn't.

In the runQueue() function I first check to see if e_running <
e_concurrent. If so, I trigger another ajax call and increment
e_running. The return handlers for the ajax call will decrement
e_running upon completion. Before existing runQueue(), I set the timer
runQueueTimer when:

  a) timer isn't already set
  b) e_running != 0
  c) count of e_pending !=0 

runQueueTimer is set for something like 1 or 2 seconds in my app. When
multiple events come in this has the nice effect of spacing out the
requests sent to the server. And of course, this avoids tight CPU
sucking JS loops on the client side as well.

I really miss JavaScript not having sleep() but this worked out well.

> secondly, i still am confused to why u think jQuery should not offer
> this support because you believe this is bad. Remember, the idea of
> ajax is to stop an entire page from loading/refreshing and only
> retrieving the data that has changed. It's very simple to look at a
> page and see three _independent_ sections that have 3 different ajax
> calls .. but please don't forget scenario's like mine .. or even one
> of the most common scenario's -> autocomplete .. we're there's multi
> requests to the same ajax service .. where the _option_ of queueing
> could be available for those who worry.
> 
> but anyways, you've answered my question :) time to hunt around for
> stuff...

Reply via email to