I'm building an HTTP request pooler in JS.  In essence the pool creates
several HTTP objects and allows the programmer to add requests to the queue.
The queue is then examined at an interval and queued requests are passed to
free objects for calls.

Anyway - all that seems to work pretty well - except setting up the
interval.

Let's assume this simplified Object:

        // Create the Pool
function HTTPRequestPool(ObInstanceCount, IntervalCount) {

                // Create a Queue for Requests
        this.RequestQueue = new Array();

        App.RequestPoolTimer = window.setInterval("this.doRequest();", 500);

};

HTTPRequestPool.prototype.addRequest = function addRequest( Method, URL,
Parameters, Handler) { }; 

HTTPRequestPool.prototype.doRequest = function doRequest() { };


We would instantiate this like this (someplace on the page):

RequestPool = new HTTPRequestPool(5, 500);

The problem is the interval - in this case the doRequest() method, when
called from the interval, loses the connection to the parent object.  When
called "this" refers to the top-level window (as it would when a top-level
function is called) NOT to the parent object (as it would when a method is
called).

However if I remove the interval from the object and instantiate things like
this (setting the interval outside of the object):

RequestPool = new HTTPRequestPool(5, 500);
App.RequestPoolTimer = window.setInterval("RequestPool.doRequest();", 500);

Everything works fine - the interval never loses its reference.

This is a workaround, but I'd much rather have the interval contained in the
object itself.

Thanks in advance for any ideas.

Jim Davis


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:235861
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to