!7 set flag ExpiringMap2_debug. static long timeout = 60000; static ExpiringMap2 recenctlyConnectedComputers_internal = new ExpiringMap2(5000, f updateValue); static new MultiSet activeConnections; static Map recentlyConnectedComputers = synchroMap(recenctlyConnectedComputers_internal); static Var connected2 = new(0); svoid updateValue { Set set1 = keys(activeConnections); Set set2 = keys(recentlyConnectedComputers); int n = l(mergeSets(set1, set2)); //int n = l(connectedComputers); connected2.set(n); print("Updated value to " + n + " (" + l(set1) + "/" + l(set2) + ")"); } p { // TODO (maybe): add countdown to ExpiringMap instead doEvery(1000, r { synchronized(recentlyConnectedComputers) { recenctlyConnectedComputers_internal.clean(); } }); } html { int count = parseIntOpt(params.get('count)); fS computerID = or2(subBot_getHeader("X-ComputerID"), "unknown"); bool longPoll = params.get('count) != null; if (computerID != null) { activeConnections.add(computerID); print("Have active connections from " + computerID + ": " + activeConnections.get(computerID)); updateValue(); } temp tempAfterwards(r { if (computerID != null) { activeConnections.remove(computerID); print("Disconnected. Have active connections from " + computerID + ": " + activeConnections.get(computerID)); updateValue(); } }); if (computerID != null) print("Got connection from " + computerID); temp tempAfterwards(r { if (computerID != null) { print("Adding recently connected computer: " + computerID); recentlyConnectedComputers.put(computerID, true); } }); if (!longPoll) ret connected2!; print(connected2! + ", eq: " + eq(connected2!, count)); waitForVarToChange_withTimeout(connected2, count, timeout); ret connected2!; }