+class Nerver():
+ # A little utility class used to run the nervlists. A nervlist is a list of (n, f) tuples where f() is run after n seconds.
+ # If f returns something, that's also returned by nerv.
+ def __init__(self, nervlist):
+ self.nervlist = list(nervlist)
+
+ def nerv(self, total_time):
+ if len(self.nervlist):
+ (time, f) = self.nervlist[0]
+ # check if the first element is to be triggered
+ if time >= total_time:
+ self.nervlist = self.nervlist[1:] # "pop" the first element, but do not modify original list
+ return f()
+
+