sclass ConnectedInstances { ExpiringMap2 recentlyConnected_internal = new ExpiringMap2(5000/*, r updateValue*/); new MultiSet activeConnections; Map recentlyConnected = synchroMap(recentlyConnected_internal); Set set; SimpleLiveValue connected2 = new(Int, 0); // filtered count void setAfterglowInterval(int ms) { recentlyConnected_internal.setStandardExpiryTime(ms); } void start() { // TODO (maybe): add countdown to ExpiringMap instead doEvery(1000, r { bool changes; synchronized(recentlyConnected) { changes = recentlyConnected_internal.clean(); } if (changes) updateValue(); }); } void updateValue { Set set1 = keys(activeConnections); Set set2 = keys(recentlyConnected); set = mergeSets(set1, set2); int n = l(set); connected2.set(n); print("Updated value to " + n + " (" + l(set1) + "/" + l(set2) + ")"); } void gotConnection(S computerID) { if (computerID != null) { activeConnections.add(computerID); print("Have active connections from " + computerID + ": " + activeConnections.get(computerID)); updateValue(); } } void lostConnection(S computerID) { if (computerID != null) { activeConnections.remove(computerID); print("Disconnected. Have active connections from " + computerID + ": " + activeConnections.get(computerID)); recentlyConnected.put(computerID, true); updateValue(); } } Set set() { ret set; } int value() { ret connected2!; } /*void waitForChange(int value, int timeout) { waitForVarToChange_withTimeout(connected2, value, timeout); }*/ }