Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.server.getRealtimeUpdates

on getRealtimeUpdates (username) {
	<<Changes
		<<7/16/10; 7:43:21 AM by DW
			<<Add another level under each users' realtimeUpdates table, with the IP they're connecting through. 
			<<Set the creation time of the table we're watching to now. If a table gets too old, it gets reclaimed, so we don't have to accumulate updates for connections that aren't being maintained.
		<<7/13/10; 8:16:06 AM by DW
			<<Wait for something to show up in the user's realtimeUpdates table, when it does, pack it up and return it. If it times out (initially hard-coded to 60 seconds) return an empty table.
	local (adrsystemdata = scripting2suite.init (), now = clock.now ());
	local (ctsecstimeout = adrsystemdata^.server.prefs.ctSecsRealtimeTimeout);
	local (startticks = clock.ticks (), maxticks = ctsecstimeout * 60);
	local (adrtable = @system.temp.scripting2.server.users.[username].realtimeUpdates.[client]);
	if not defined (adrtable^) {
		new (tabletype, adrtable)};
	setTimeCreated (adrtable, now);
	setTimeModified (adrtable, now);
	local (semaphore = scripting2Suite.data.misc.realtimeSemaphore);
	loop {
		if sizeof (adrtable^) > 0 {
			local (t);
			semaphore.lock (semaphore, 180);
			t = adrtable^; //copy it
			new (tabletype, adrtable); //consume it
			semaphore.unlock (semaphore);
			return (t)}; //return it
		if (clock.ticks () - startticks) > maxticks { //return an empty table
			local (t);
			new (tabletype, @t);
			return (t)};
		thread.sleepfor (1)}} //sleep for a second



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.