Last active
June 7, 2018 20:30
-
-
Save mashumafi/7b76d6b52b7546d77c6b9845dfea43ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def listen_event(self, event, *args, **kwargs): | |
'''Fires an event.''' | |
events = self.__events.get(event, {}) | |
for key in events: | |
for val in events[key](*args, **kwargs): | |
yield val | |
# example | |
emitter = EventEmitter() | |
def one_to_ten(): | |
for i in range(10): | |
yield i | |
emitter.on('one_to_ten', one_to_ten, "key1") | |
emitter.on('one_to_ten', one_to_ten, "key2") | |
for i in emitter.listen_event("one_to_ten"): | |
print(i) | |
# prints 1-10 twice? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment