Skip to content

Commit

Permalink
say goodbye when gracefully disconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed May 15, 2023
1 parent 7280db7 commit 35782c5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ impl Drop for RecordingStreamInner {
// sending data down the pipeline.
self.batcher.flush_blocking();
self.cmds_tx.send(Command::PopPendingTables).ok();
// Announce we're gracefully leaving to the other end.
self.cmds_tx
.send(Command::RecordMsg(LogMsg::Goodbye(
self.info.recording_id.clone(),
Expand Down Expand Up @@ -771,12 +772,25 @@ impl RecordingStream {
Ok(())
}

/// Swaps the underlying sink for a [`crate::sink::BufferedSink`].
/// Swaps the underlying sink for a [`crate::sink::BufferedSink`], making sure to first send a
/// `Goodbye` message down the sink to let the other end know of the graceful disconnection.
///
/// This is a convenience wrapper for [`Self::set_sink`] that upholds the same guarantees in
/// terms of data durability and ordering.
/// See [`Self::set_sink`] for more information.
pub fn disconnect(&self) {
let Some(this) = &*self.inner else {
re_log::warn_once!("Recording disabled - call to disconnect() ignored");
return;
};

this.cmds_tx
.send(Command::RecordMsg(LogMsg::Goodbye(
this.info.recording_id.clone(),
RowId::random(),
)))
.ok();

self.set_sink(Box::new(crate::sink::BufferedSink::new()));
}
}
Expand Down

0 comments on commit 35782c5

Please sign in to comment.