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

scripting2Suite.data.code.realtime.server.getUpdates

on getUpdates (username, ipaddress) {
	<<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 (adrdata = realtime.init (), now = clock.now ());
	local (timeoutticks = clock.ticks () + (adrdata^.server.prefs.ctSecsTimeout * 60));
	local (adrinbox = realtime.server.initinbox (username, ipaddress));
	local (sem = realtime.server.data.semaphoreName);
	adrinbox^.stats.whenLastCheck = now; adrinbox^.stats.ctChecks++;
	loop {
		if sizeof (adrinbox^.queue) > 0 {
			local (t);
			semaphore.lock (sem, 180);
			t = adrinbox^.queue;
			new (tabletype, @adrinbox^.queue); //consume it
			semaphore.unlock (sem);
			adrinbox^.stats.ctNonTimeouts++;
			return (t)}; //return it
		if clock.ticks () > timeoutticks { //return an empty table
			local (t);
			new (tabletype, @t);
			adrinbox^.stats.ctTimeouts++;
			return (t)};
		thread.sleepfor (1); //sleep for a second
		adrinbox^.stats.ctLoops++}};
bundle { //test code
	scratchpad.updates = getUpdates ("davewiner", tcp.dns.getmydottedid ())}



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.