@@ -14,23 +14,39 @@ use crate::pyroscope::PyroscopeConfig;
1414use crate :: utils:: merge_tags_with_app_name;
1515use crate :: Result ;
1616
17+ /// Session Signal
18+ #[ derive( Debug ) ]
19+ pub enum SessionSignal {
20+ Session ( Session ) ,
21+ Kill ,
22+ }
23+
1724/// SessionManager
1825#[ derive( Debug ) ]
1926pub struct SessionManager {
2027 pub handle : Option < JoinHandle < Result < ( ) > > > ,
21- pub tx : SyncSender < Session > ,
28+ pub tx : SyncSender < SessionSignal > ,
2229}
2330
2431impl SessionManager {
2532 /// Create a new SessionManager
2633 pub fn new ( ) -> Result < Self > {
2734 // Create a channel for sending and receiving sessions
28- let ( tx, rx) : ( SyncSender < Session > , Receiver < Session > ) = sync_channel ( 10 ) ;
35+ let ( tx, rx) : ( SyncSender < SessionSignal > , Receiver < SessionSignal > ) = sync_channel ( 10 ) ;
2936
3037 // Create a thread for the SessionManager
3138 let handle = Some ( thread:: spawn ( move || {
32- while let Ok ( session) = rx. recv ( ) {
33- session. send ( ) ?;
39+ while let Ok ( signal) = rx. recv ( ) {
40+ match signal {
41+ SessionSignal :: Session ( session) => {
42+ // Send the session
43+ session. send ( ) ?;
44+ }
45+ SessionSignal :: Kill => {
46+ // Kill the session manager
47+ return Ok ( ( ) ) ;
48+ }
49+ }
3450 }
3551 Ok ( ( ) )
3652 } ) ) ;
@@ -39,7 +55,7 @@ impl SessionManager {
3955 }
4056
4157 /// Push a new session into the SessionManager
42- pub fn push ( & self , session : Session ) -> Result < ( ) > {
58+ pub fn push ( & self , session : SessionSignal ) -> Result < ( ) > {
4359 self . tx . send ( session) ?;
4460 Ok ( ( ) )
4561 }
0 commit comments