function getUsers(column, id) {
	$.get('userlist.php', {column: column, id: id}, function(output) {
	setTimeout(getUsers(column, id), 5000);

userlist.php checks for users online.

i want it to check every 5000ms (for example, doesnt have to be that)

Firebug is giving me 'too much recursion' errors.

I've used this exact code structure before successfully.... help would be greatly appreciated!

7 Years
Discussion Span
Last Post by Airshow


This is tricky.

I'm not sure why the code works at all because setTimeout(getUsers(column, id), 5000); appears to be invalid. I would choose to use setTimeout(function()(getUsers(column, id);), 5000); . This might in itself fix the bug.

Thoughts ....
Strictly speaking there's no recursion, as setTimeout starts a fresh call-stack at each iteration. However, the presence of column, id as arguments means that these variables are held in a fresh, nested closure at each iteration. At some threshold, the number of nested closures (rather than recusions per se) exceeds the number allowed by the javascript engine. In this regard, the difference between recursions and nested closures is somewhat academic.

If I'm right (and my first suggestion doesn't work), then the workaround is not to pass column, id to getUsers . Instead, set column and id as outer variables (global if you must) at the point where getUsers is first called. This will avoid the need for closures and should allow garbage collection to do its thing.


Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.