@@ -231,10 +231,22 @@ impl Relay {
231
231
self . inner . internal_notification_sender . subscribe ( )
232
232
}
233
233
234
- /// Connect to relay
234
+ /// Connect to the relay
235
+ ///
236
+ /// # Overview
237
+ ///
238
+ /// If the relay’s status is not [`RelayStatus::Initialized`] or [`RelayStatus::Terminated`],
239
+ /// this method returns immediately without doing anything.
240
+ /// Otherwise, the connection task will be spawned, which will attempt to connect to relay.
235
241
///
236
242
/// This method returns immediately and doesn't provide any information on if the connection was successful or not.
243
+ ///
244
+ /// # Automatic reconnection
245
+ ///
246
+ /// By default, in case of disconnection, the connection task will automatically attempt to reconnect.
247
+ /// This behavior can be disabled by changing [`RelayOptions::reconnect`] option.
237
248
pub fn connect ( & self ) {
249
+ // Immediately return if can't connect
238
250
if !self . status ( ) . can_connect ( ) {
239
251
return ;
240
252
}
@@ -279,12 +291,22 @@ impl Relay {
279
291
280
292
/// Try to establish a connection with the relay.
281
293
///
282
- /// Attempts to establish a connection without spawning the connection task if it fails.
294
+ /// # Overview
295
+ ///
296
+ /// If the relay’s status is not [`RelayStatus::Initialized`] or [`RelayStatus::Terminated`],
297
+ /// this method returns immediately without doing anything.
298
+ /// Otherwise, attempts to establish a connection without spawning the connection task if it fails.
283
299
/// This means that if the connection fails, no automatic retries are scheduled.
284
300
/// Use [`Relay::connect`] if you want to immediately spawn a connection task,
285
301
/// regardless of whether the initial connection succeeds.
286
302
///
287
303
/// Returns an error if the connection fails.
304
+ ///
305
+ /// # Automatic reconnection
306
+ ///
307
+ /// By default, in case of disconnection (after a first successful connection),
308
+ /// the connection task will automatically attempt to reconnect.
309
+ /// This behavior can be disabled by changing [`RelayOptions::reconnect`] option.
288
310
pub async fn try_connect ( & self , timeout : Duration ) -> Result < ( ) , Error > {
289
311
// Check if relay can't connect
290
312
if !self . status ( ) . can_connect ( ) {
@@ -304,7 +326,9 @@ impl Relay {
304
326
Ok ( ( ) )
305
327
}
306
328
307
- /// Disconnect from relay and set status to 'Terminated'
329
+ /// Disconnect from relay and set status to [`RelayStatus::Terminated`].
330
+ ///
331
+ /// Returns immediately if the status is already [`RelayStatus::Terminated`].
308
332
#[ inline]
309
333
pub fn disconnect ( & self ) {
310
334
self . inner . disconnect ( )
0 commit comments