@@ -15,15 +15,24 @@ const MAX_QUEUE_SIZE: usize = 256;
1515type ArcMx < T > = Arc < Mutex < T > > ;
1616type CompilationEventChannel = mpsc:: Sender < Arc < dyn CompilationEvent > > ;
1717
18+ #[ derive( Debug , Clone , Eq , PartialEq , Hash , serde:: Serialize , serde:: Deserialize ) ]
19+ enum EventChannelType {
20+ Global ,
21+ Type ( String ) ,
22+ }
23+
1824pub struct CompilationEventQueue {
1925 event_history : ArcMx < VecDeque < Arc < dyn CompilationEvent > > > ,
20- subscribers : Arc < DashMap < String , Vec < CompilationEventChannel > > > ,
26+ subscribers : Arc < DashMap < EventChannelType , Vec < CompilationEventChannel > > > ,
2127}
2228
2329impl Default for CompilationEventQueue {
2430 fn default ( ) -> Self {
2531 let subscribers = DashMap :: new ( ) ;
26- subscribers. insert ( "*" . to_owned ( ) , Vec :: < CompilationEventChannel > :: new ( ) ) ;
32+ subscribers. insert (
33+ EventChannelType :: Global ,
34+ Vec :: < CompilationEventChannel > :: new ( ) ,
35+ ) ;
2736
2837 Self {
2938 event_history : Arc :: new ( Mutex :: new ( VecDeque :: with_capacity ( MAX_QUEUE_SIZE ) ) ) ,
@@ -51,7 +60,9 @@ impl CompilationEventQueue {
5160 history. push_back ( message_clone. clone ( ) ) ;
5261
5362 // Send to all active receivers of the same message type
54- if let Some ( mut type_subscribers) = subscribers. get_mut ( message_clone. type_name ( ) ) {
63+ if let Some ( mut type_subscribers) = subscribers. get_mut ( & EventChannelType :: Type (
64+ message_clone. type_name ( ) . to_owned ( ) ,
65+ ) ) {
5566 let mut removal_indices = Vec :: new ( ) ;
5667 for ( ix, sender) in type_subscribers. iter ( ) . enumerate ( ) {
5768 if sender. send ( message_clone. clone ( ) ) . await . is_err ( ) {
@@ -65,7 +76,7 @@ impl CompilationEventQueue {
6576 }
6677
6778 // Send to all global message subscribers
68- let mut all_channel = subscribers. get_mut ( "*" ) . unwrap ( ) ;
79+ let mut all_channel = subscribers. get_mut ( & EventChannelType :: Global ) . unwrap ( ) ;
6980 let mut removal_indices = Vec :: new ( ) ;
7081 for ( ix, sender) in all_channel. iter_mut ( ) . enumerate ( ) {
7182 if sender. send ( message_clone. clone ( ) ) . await . is_err ( ) {
@@ -95,7 +106,9 @@ impl CompilationEventQueue {
95106 // Store the sender
96107 if let Some ( event_types) = event_types {
97108 for event_type in event_types. iter ( ) {
98- let mut type_subscribers = subscribers. entry ( event_type. clone ( ) ) . or_default ( ) ;
109+ let mut type_subscribers = subscribers
110+ . entry ( EventChannelType :: Type ( event_type. clone ( ) ) )
111+ . or_default ( ) ;
99112 type_subscribers. push ( tx_clone. clone ( ) ) ;
100113 }
101114
@@ -105,7 +118,8 @@ impl CompilationEventQueue {
105118 }
106119 }
107120 } else {
108- let mut global_subscribers = subscribers. entry ( "*" . to_string ( ) ) . or_default ( ) ;
121+ let mut global_subscribers =
122+ subscribers. entry ( EventChannelType :: Global ) . or_default ( ) ;
109123 global_subscribers. push ( tx_clone. clone ( ) ) ;
110124
111125 for event in event_history. lock ( ) . await . iter ( ) {
0 commit comments