<s> import threading <EOL> from time import sleep <EOL> class EventEmitter ( object ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _observers = { } <EOL> def on ( self , event , cb ) : <EOL> if event not in self . _observers : <EOL> self . _observers [ event ] = [ cb , ] <EOL> else : <EOL> if cb not in self . _observers [ event ] : <EOL> self . _observers [ event ] . append ( cb ) <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" , <EOL> event ) <EOL> def off ( self , event , cb ) : <EOL> if event not in self . _observers : <EOL> raise KeyError ( <EOL> "<STR_LIT>" , <EOL> event ) <EOL> else : <EOL> if cb not in self . _observers [ event ] : <EOL> raise ValueError ( <EOL> "<STR_LIT>" , <EOL> event ) <EOL> else : <EOL> self . _observers [ event ] . remove ( cb ) <EOL> def emit ( self , event , * args ) : <EOL> if event in self . _observers : <EOL> for observer in self . _observers [ event ] : <EOL> observer ( * args ) <EOL> def debounce ( wait ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( fn ) : <EOL> def debounced ( * args , ** kwargs ) : <EOL> def call_it ( ) : <EOL> fn ( * args , ** kwargs ) <EOL> try : <EOL> debounced . t . cancel ( ) <EOL> except ( AttributeError ) : <EOL> pass <EOL> debounced . t = threading . Timer ( wait , call_it ) <EOL> debounced . t . start ( ) <EOL> return debounced <EOL> return decorator <EOL> class setInterval ( threading . Thread ) : <EOL> def __init__ ( self , func , millis ) : <EOL> threading . Thread . __init__ ( self ) <EOL> self . event = threading . Event ( ) <EOL> self . func = func <EOL> self . seconds = millis / <NUM_LIT> <EOL> self . shouldRun = True <EOL> self . setDaemon ( True ) <EOL> self . start ( ) <EOL> def run ( self ) : <EOL> while self . shouldRun : <EOL> self . func ( ) <EOL> sleep ( self . seconds ) <EOL> def clear ( self ) : <EOL> self . shouldRun = False </s>
