comparison libervia/backend/tools/async_trigger.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents e11b13418ba6
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
24 from libervia.backend.core.xmpp import SatXMPPEntity 24 from libervia.backend.core.xmpp import SatXMPPEntity
25 from . import trigger as sync_trigger 25 from . import trigger as sync_trigger
26 from . import utils 26 from . import utils
27 from twisted.internet import defer 27 from twisted.internet import defer
28 28
29
29 class TriggerManager(sync_trigger.TriggerManager): 30 class TriggerManager(sync_trigger.TriggerManager):
30 """This is a TriggerManager with an new async_point method""" 31 """This is a TriggerManager with an new async_point method"""
31 32
32 async def async_point( 33 async def async_point(self, point_name: str, *args, **kwargs) -> bool:
33 self,
34 point_name: str,
35 *args, **kwargs
36 ) -> bool:
37 """This put a trigger point with potentially async Deferred 34 """This put a trigger point with potentially async Deferred
38 35
39 All the triggers for that point will be run 36 All the triggers for that point will be run
40 @param point_name: name of the trigger point 37 @param point_name: name of the trigger point
41 @param *args: args to transmit to trigger 38 @param *args: args to transmit to trigger
46 @return D(bool): True if the action must be continued, False else 43 @return D(bool): True if the action must be continued, False else
47 """ 44 """
48 if point_name not in self.__triggers: 45 if point_name not in self.__triggers:
49 return True 46 return True
50 47
51 can_cancel = not kwargs.pop('triggers_no_cancel', False) 48 can_cancel = not kwargs.pop("triggers_no_cancel", False)
52 49
53 for __, trigger in self.__triggers[point_name]: 50 for __, trigger in self.__triggers[point_name]:
54 try: 51 try:
55 cont = await utils.as_deferred(trigger, *args, **kwargs) 52 cont = await utils.as_deferred(trigger, *args, **kwargs)
56 if can_cancel and not cont: 53 if can_cancel and not cont:
58 except sync_trigger.SkipOtherTriggers: 55 except sync_trigger.SkipOtherTriggers:
59 break 56 break
60 return True 57 return True
61 58
62 async def async_return_point( 59 async def async_return_point(
63 self, 60 self, point_name: str, *args, **kwargs
64 point_name: str,
65 *args, **kwargs
66 ) -> Tuple[bool, Any]: 61 ) -> Tuple[bool, Any]:
67 """Async version of return_point""" 62 """Async version of return_point"""
68 if point_name not in self.__triggers: 63 if point_name not in self.__triggers:
69 return True, None 64 return True, None
70 65
74 if not cont: 69 if not cont:
75 return False, ret_value 70 return False, ret_value
76 except sync_trigger.SkipOtherTriggers: 71 except sync_trigger.SkipOtherTriggers:
77 break 72 break
78 return True, None 73 return True, None
79