#cbk.py
registryList = []
def registry(f):
"""To append in registryList"""
def callbackRegistration():
registryList.append(f())
return f
callbackRegistration()
def predicate1(e):
if e[0] == 'data':
return True
def action1(e, eventLoop):
print('do whatever')
@registry
def registerCallback():
"""Must be the provider of multiple callbacks(if any)"""
return (predicate1, action1)
#cbk-registration.py
from cbk import registryList
if __name__ == '__main__':
genEvent = ('data', 1.2)
for pred, action in registryList:
if pred(genEvent) == True:
action(genEvent, None)
In cbk.py, predicate1 & action1 are scattered.
Is there a design pattern to add multiple callbacks (pred,action)?
Aucun commentaire:
Enregistrer un commentaire