Some checks failed
Build Dusk / build-linux (push) Failing after 1m24s
Build Dusk / run-tests (push) Failing after 1m17s
Build Dusk / build-psp (push) Failing after 1m34s
Build Dusk / build-dolphin (push) Failing after 2m5s
19 lines
544 B
Python
19 lines
544 B
Python
class Event:
|
|
def __init__(self):
|
|
self._subscribers = []
|
|
|
|
def sub(self, callback):
|
|
"""Subscribe a callback to the event."""
|
|
if callback not in self._subscribers:
|
|
self._subscribers.append(callback)
|
|
|
|
def unsub(self, callback):
|
|
"""Unsubscribe a callback from the event."""
|
|
if callback in self._subscribers:
|
|
self._subscribers.remove(callback)
|
|
|
|
def invoke(self, *args, **kwargs):
|
|
"""Invoke all subscribers with the given arguments."""
|
|
for callback in self._subscribers:
|
|
callback(*args, **kwargs)
|