comparison sat/tools/async_trigger.py @ 3397:c069882f64cb

tools (async_trigger): use `utils.asDeferred` for async triggers: A corouting or blocking method can now be used for async triggers.
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:15 +0100
parents 559a625a236b
children be6d91572633
comparison
equal deleted inserted replaced
3396:a4774f5b6b17 3397:c069882f64cb
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 """Misc usefull classes""" 20 """Misc usefull classes"""
21 21
22 from sat.tools import trigger as sync_trigger 22 from . import trigger as sync_trigger
23 from . import utils
23 from twisted.internet import defer 24 from twisted.internet import defer
24 25
25 class TriggerManager(sync_trigger.TriggerManager): 26 class TriggerManager(sync_trigger.TriggerManager):
26 """This is a TriggerManager with an new asyncPoint method""" 27 """This is a TriggerManager with an new asyncPoint method"""
27 28
43 44
44 can_cancel = not kwargs.pop('triggers_no_cancel', False) 45 can_cancel = not kwargs.pop('triggers_no_cancel', False)
45 46
46 for priority, trigger in self.__triggers[point_name]: 47 for priority, trigger in self.__triggers[point_name]:
47 try: 48 try:
48 cont = yield trigger(*args, **kwargs) 49 cont = yield utils.asDeferred(trigger, *args, **kwargs)
49 if can_cancel and not cont: 50 if can_cancel and not cont:
50 defer.returnValue(False) 51 defer.returnValue(False)
51 except sync_trigger.SkipOtherTriggers: 52 except sync_trigger.SkipOtherTriggers:
52 break 53 break
53 defer.returnValue(True) 54 defer.returnValue(True)