19 lines
398 B
Python
19 lines
398 B
Python
|
# Copyright 2020 (c) Anna Schumaker.
|
||
|
|
||
|
class Publisher:
|
||
|
def __init__(self):
|
||
|
self.subscribers = set()
|
||
|
|
||
|
def publish(self, *args):
|
||
|
for func in self.subscribers:
|
||
|
func(*args)
|
||
|
|
||
|
def register(self, func):
|
||
|
self.subscribers.add(func)
|
||
|
|
||
|
def reset(self):
|
||
|
self.subscribers.clear()
|
||
|
|
||
|
def unregister(self, func):
|
||
|
self.subscribers.discard(func)
|