@@ -13,6 +13,8 @@ pub use input_source::*;
13
13
mod muxed_message;
14
14
pub use muxed_message:: * ;
15
15
16
+ use crate :: models:: Config ;
17
+
16
18
pub trait Message : Sized {
17
19
type Data ;
18
20
@@ -66,6 +68,11 @@ impl Global {
66
68
pub async fn subscribe_muxed ( & self ) -> broadcast:: Receiver < MuxedMessage > {
67
69
self . 0 . read ( ) . await . muxed_tx . subscribe ( )
68
70
}
71
+
72
+ pub async fn read_config < T > ( & self , f : impl FnOnce ( & Config ) -> T ) -> T {
73
+ let data = self . 0 . read ( ) . await ;
74
+ f ( & data. config )
75
+ }
69
76
}
70
77
71
78
pub struct GlobalData {
@@ -75,10 +82,11 @@ pub struct GlobalData {
75
82
next_input_source_id : usize ,
76
83
muxed_sources : HashMap < usize , Arc < InputSource < MuxedMessage > > > ,
77
84
next_muxed_source_id : usize ,
85
+ config : Config ,
78
86
}
79
87
80
88
impl GlobalData {
81
- pub fn new ( ) -> Self {
89
+ pub fn new ( config : & Config ) -> Self {
82
90
let ( input_tx, _) = broadcast:: channel ( 4 ) ;
83
91
let ( muxed_tx, _) = broadcast:: channel ( 4 ) ;
84
92
@@ -89,6 +97,7 @@ impl GlobalData {
89
97
next_input_source_id : 1 ,
90
98
muxed_sources : Default :: default ( ) ,
91
99
next_muxed_source_id : 1 ,
100
+ config : config. clone ( ) ,
92
101
}
93
102
}
94
103
0 commit comments