@@ -13,7 +13,7 @@ type SharedStoreSubscriber = RwLock<Box<dyn StoreSubscriber>>;
13
13
//
14
14
// TODO(#4204): StoreSubscriber should require SizeBytes so they can be part of memstats.
15
15
pub trait StoreSubscriber : std:: any:: Any + Send + Sync {
16
- /// Arbitrary name for the view .
16
+ /// Arbitrary name for the subscriber .
17
17
///
18
18
/// Does not need to be unique.
19
19
fn name ( & self ) -> String ;
@@ -36,7 +36,7 @@ pub trait StoreSubscriber: std::any::Any + Send + Sync {
36
36
37
37
/// The core of this trait: get notified of changes happening in all [`DataStore`]s.
38
38
///
39
- /// This will be called automatically by the [`DataStore`] itself if the view has been
39
+ /// This will be called automatically by the [`DataStore`] itself if the subscriber has been
40
40
/// registered: [`DataStore::register_subscriber`].
41
41
/// Or you might want to feed it [`StoreEvent`]s manually, depending on your use case.
42
42
///
@@ -72,65 +72,67 @@ impl DataStore {
72
72
/// ## Scope
73
73
///
74
74
/// Registered [`StoreSubscriber`]s are global scope: they get notified of all events from all
75
- /// existing [`DataStore`]s, including [`DataStore`]s created after the view was registered.
75
+ /// existing [`DataStore`]s, including [`DataStore`]s created after the subscriber was registered.
76
76
///
77
77
/// Use [`StoreEvent::store_id`] to identify the source of an event.
78
78
///
79
79
/// ## Late registration
80
80
///
81
- /// Views must be registered before a store gets created to guarantee that no events were
82
- /// missed.
81
+ /// Subscribers must be registered before a store gets created to guarantee that no events
82
+ /// were missed.
83
83
///
84
84
/// [`StoreEvent::event_id`] can be used to identify missing events.
85
85
///
86
86
/// ## Ordering
87
87
///
88
- /// The order in which registered views are notified is undefined and will likely become
88
+ /// The order in which registered subscribers are notified is undefined and will likely become
89
89
/// concurrent in the future.
90
90
///
91
- /// If you need a specific order across multiple views, embed them into an orchestrating view.
91
+ /// If you need a specific order across multiple subscribers, embed them into an orchestrating
92
+ /// subscriber.
92
93
//
93
94
// TODO(cmc): send a compacted snapshot to late registerers for bootstrapping
94
- pub fn register_subscriber ( view : Box < dyn StoreSubscriber > ) -> StoreSubscriberHandle {
95
- let mut views = SUBSCRIBERS . write ( ) ;
96
- views . push ( RwLock :: new ( view ) ) ;
97
- StoreSubscriberHandle ( views . len ( ) as u32 - 1 )
95
+ pub fn register_subscriber ( subscriber : Box < dyn StoreSubscriber > ) -> StoreSubscriberHandle {
96
+ let mut subscribers = SUBSCRIBERS . write ( ) ;
97
+ subscribers . push ( RwLock :: new ( subscriber ) ) ;
98
+ StoreSubscriberHandle ( subscribers . len ( ) as u32 - 1 )
98
99
}
99
100
100
- /// Passes a reference to the downcasted view to the given callback.
101
+ /// Passes a reference to the downcasted subscriber to the given callback.
101
102
///
102
- /// Returns `None` if the view doesn't exist or downcasting failed.
103
+ /// Returns `None` if the subscriber doesn't exist or downcasting failed.
103
104
pub fn with_subscriber < V : StoreSubscriber , T , F : FnMut ( & V ) -> T > (
104
105
StoreSubscriberHandle ( handle) : StoreSubscriberHandle ,
105
106
mut f : F ,
106
107
) -> Option < T > {
107
- let views = SUBSCRIBERS . read ( ) ;
108
- views . get ( handle as usize ) . and_then ( |view | {
109
- let view = view . read ( ) ;
110
- view . as_any ( ) . downcast_ref :: < V > ( ) . map ( & mut f)
108
+ let subscribers = SUBSCRIBERS . read ( ) ;
109
+ subscribers . get ( handle as usize ) . and_then ( |subscriber | {
110
+ let subscriber = subscriber . read ( ) ;
111
+ subscriber . as_any ( ) . downcast_ref :: < V > ( ) . map ( & mut f)
111
112
} )
112
113
}
113
114
114
- /// Passes a mutable reference to the downcasted view to the given callback.
115
+ /// Passes a mutable reference to the downcasted subscriber to the given callback.
115
116
///
116
- /// Returns `None` if the view doesn't exist or downcasting failed.
117
+ /// Returns `None` if the subscriber doesn't exist or downcasting failed.
117
118
pub fn with_subscriber_mut < V : StoreSubscriber , T , F : FnMut ( & mut V ) -> T > (
118
119
StoreSubscriberHandle ( handle) : StoreSubscriberHandle ,
119
120
mut f : F ,
120
121
) -> Option < T > {
121
- let views = SUBSCRIBERS . read ( ) ;
122
- views . get ( handle as usize ) . and_then ( |view | {
123
- let mut view = view . write ( ) ;
124
- view . as_any_mut ( ) . downcast_mut :: < V > ( ) . map ( & mut f)
122
+ let subscribers = SUBSCRIBERS . read ( ) ;
123
+ subscribers . get ( handle as usize ) . and_then ( |subscriber | {
124
+ let mut subscriber = subscriber . write ( ) ;
125
+ subscriber . as_any_mut ( ) . downcast_mut :: < V > ( ) . map ( & mut f)
125
126
} )
126
127
}
127
128
128
- /// Called by [`DataStore`]'s mutating methods to notify view subscribers of upcoming events.
129
+ /// Called by [`DataStore`]'s mutating methods to notify subscriber subscribers of upcoming events.
129
130
pub ( crate ) fn on_events ( events : & [ StoreEvent ] ) {
130
- let views = SUBSCRIBERS . read ( ) ;
131
+ re_tracing:: profile_function!( ) ;
132
+ let subscribers = SUBSCRIBERS . read ( ) ;
131
133
// TODO(cmc): might want to parallelize at some point.
132
- for view in views . iter ( ) {
133
- view . write ( ) . on_events ( events) ;
134
+ for subscriber in subscribers . iter ( ) {
135
+ subscriber . write ( ) . on_events ( events) ;
134
136
}
135
137
}
136
138
}
0 commit comments