@@ -25,6 +25,7 @@ pub struct ClientOptions {
25
25
pub ( super ) connection : Connection ,
26
26
pub ( super ) relay_limits : RelayLimits ,
27
27
pub ( super ) max_avg_latency : Option < Duration > ,
28
+ pub ( super ) sleep_when_idle : SleepWhenIdle ,
28
29
pub ( super ) pool : RelayPoolOptions ,
29
30
}
30
31
@@ -99,6 +100,13 @@ impl ClientOptions {
99
100
self
100
101
}
101
102
103
+ /// Set sleep when idle config
104
+ #[ inline]
105
+ pub fn sleep_when_idle ( mut self , config : SleepWhenIdle ) -> Self {
106
+ self . sleep_when_idle = config;
107
+ self
108
+ }
109
+
102
110
/// Notification channel size (default: [`DEFAULT_NOTIFICATION_CHANNEL_SIZE`])
103
111
#[ deprecated( since = "0.42.0" , note = "Use `Options::pool` instead." ) ]
104
112
pub fn notification_channel_size ( mut self , size : usize ) -> Self {
@@ -114,6 +122,21 @@ impl ClientOptions {
114
122
}
115
123
}
116
124
125
+ /// Put relays to sleep when idle.
126
+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
127
+ pub enum SleepWhenIdle {
128
+ /// Disabled
129
+ #[ default]
130
+ Disabled ,
131
+ /// Enabled for all relays
132
+ Enabled {
133
+ /// Idle timeout
134
+ ///
135
+ /// After how much time of inactivity put the relay to sleep.
136
+ timeout : Duration ,
137
+ } ,
138
+ }
139
+
117
140
/// Connection target
118
141
#[ cfg( not( target_arch = "wasm32" ) ) ]
119
142
#[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash ) ]
0 commit comments