Registers a closure that will get called when the value for the specified [`VarDefinition`] changes. The callback is guaranteed to be called at least once.
(
&mut self,
var: &VarDefinition,
callback: Arc<dyn Fn(&SystemVars) + Send + Sync>,
)
| 1608 | /// |
| 1609 | /// The callback is guaranteed to be called at least once. |
| 1610 | pub fn register_callback( |
| 1611 | &mut self, |
| 1612 | var: &VarDefinition, |
| 1613 | callback: Arc<dyn Fn(&SystemVars) + Send + Sync>, |
| 1614 | ) { |
| 1615 | self.callbacks |
| 1616 | .entry(var.name().to_string()) |
| 1617 | .or_default() |
| 1618 | .push(callback); |
| 1619 | self.notify_callbacks(var.name()); |
| 1620 | } |
| 1621 | |
| 1622 | /// Notify any external components interested in this variable. |
| 1623 | fn notify_callbacks(&self, name: &str) { |