From 11fbea41612bef6951c2aea10bc4c078515a84f6 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 11 Nov 2015 17:09:07 +0800 Subject: [PATCH] sync_struct/Subscriber: support lists of notify callbacks --- artiq/protocols/sync_struct.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/artiq/protocols/sync_struct.py b/artiq/protocols/sync_struct.py index 635885157..5c82ffa07 100644 --- a/artiq/protocols/sync_struct.py +++ b/artiq/protocols/sync_struct.py @@ -51,11 +51,16 @@ class Subscriber: :param notify_cb: An optional function called every time a mod is received from the publisher. The mod is passed as parameter. The function is called after the mod has been processed. + A list of functions may also be used, and they will be called in turn. """ def __init__(self, notifier_name, target_builder, notify_cb=None): self.notifier_name = notifier_name self.target_builder = target_builder - self.notify_cb = notify_cb + if notify_cb is None: + notify_cb = [] + if not isinstance(notify_cb, list): + notify_cb = [notify_cb] + self.notify_cbs = notify_cb async def connect(self, host, port, before_receive_cb=None): self.reader, self.writer = \ @@ -97,8 +102,8 @@ class Subscriber: else: process_mod(target, mod) - if self.notify_cb is not None: - self.notify_cb(mod) + for notify_cb in self.notify_cbs: + notify_cb(mod) class Notifier: