@@ -69,7 +69,7 @@ def __init__(
69
69
self .child_conn : Connection | None = None
70
70
self .subscription_process : Process | None = None
71
71
self ._create_subscription_process (start_listening )
72
- self .update_callback : Optional [Callable ] = None
72
+ self .update_callback : Optional [Callable [[ None ], None ] ] = None
73
73
74
74
def __del__ (self ) -> None :
75
75
self ._cleanup_connections_and_processes ()
@@ -129,7 +129,7 @@ def _cleanup_connections_and_processes(self) -> None:
129
129
self .subscription_process .terminate ()
130
130
self .subscription_process = None
131
131
132
- def set_update_callback (self , update_handler : Callable ):
132
+ def set_update_callback (self , update_handler : Optional [ Callable [[ None ], None ]] ):
133
133
"""
134
134
Set the handler called, when the Watcher detects an update.
135
135
Recommendation: `casbin_enforcer.adapter.load_policy`
@@ -164,7 +164,10 @@ def should_reload(self) -> bool:
164
164
try :
165
165
if self .parent_conn .poll ():
166
166
message = int (self .parent_conn .recv ())
167
- return message == _ChannelSubscriptionMessage .RECEIVED_UPDATE
167
+ received_update = message == _ChannelSubscriptionMessage .RECEIVED_UPDATE
168
+ if received_update and self .update_callback is not None :
169
+ self .update_callback ()
170
+ return received_update
168
171
except EOFError :
169
172
self .logger .warning (
170
173
"Child casbin-watcher subscribe process has stopped, "
0 commit comments