- Notifications
You must be signed in to change notification settings - Fork 586
Refactor re_smart_channel -> re_log_channel #12052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| Web viewer failed to build.
View image diff on kitdiff. Note: This comment is updated whenever you push a commit. |
1abaaaf to 196c4ef Compare 196c4ef to b4917a1 Compare | use crate::{Channel, LogSource, SendError, SmartMessage, SmartMessagePayload}; | ||
| | ||
| #[derive(Clone)] | ||
| pub struct LogSender { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason git didn't realize this is mostly a rename of the old sender file, but with generics removed
| | ||
| use crate::{Channel, LogSource, SmartMessage, TryRecvError}; | ||
| | ||
| pub struct LogReceiver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly a rename of the old receiver file, but with generics removed
| /// Call this on each sent message. | ||
| /// | ||
| /// Can be used to wake up the receiver thread. | ||
| pub fn set_waker(&self, waker: impl Fn() + Send + Sync + 'static) { | ||
| *self.channel.waker.write() = Some(Box::new(waker)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is new though
lucasmerlin left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
| /// Used to indicate that a sender has left. | ||
| /// | ||
| /// This sends a message down the channel allowing the receiving end to know whether one of the | ||
| /// sender has left, and if so why (if applicable). | ||
| /// | ||
| /// Using a [`LogSender`] after calling `quit` is undefined behavior: the receiving end is free | ||
| /// to silently drop those messages (or worse). | ||
| pub fn quit( | ||
| &self, | ||
| err: Option<Box<dyn std::error::Error + Send>>, | ||
| ) -> Result<(), SendError<Box<SmartMessage>>> { | ||
| self.tx | ||
| .send(SmartMessage { | ||
| source: Arc::clone(&self.source), | ||
| payload: SmartMessagePayload::Quit(err), | ||
| }) | ||
| .map_err(|SendError(msg)| SendError(Box::new(msg)))?; | ||
| | ||
| if let Some(waker) = self.channel.waker.read().as_ref() { | ||
| (waker)(); | ||
| } | ||
| | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should dropping the Sender also call Quit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - the Quit shows intention. I'll add a comment to that effect.
Also the LogSender is clonable, so we really don't wanna quit on drop.
| /// ⚠️ This function must be called from the main thread since some platforms require that | ||
| /// their UI runs on the main thread! ⚠️ | ||
| pub fn show(main_thread_token: crate::MainThreadToken, msgs: Vec<LogMsg>) -> eframe::Result { | ||
| let log_source = re_log_channel::LogSource::Sdk; // Whatever. Nobody is really using this functions anyhow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why not get rid of this? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's part of our public API. We can mark it #[deprecated] but that feels out-of-bounds for this PR
re_smart_channelis a monster that has evolved over time.This takes a big step towards simplifying it
re_smart_channeltore_log_channelDataSourceMessagenowSender<T>/Receiver<T>toLogSender/LogReceiverSmartMessageSourceandSmartChannelSourceinto a singleLogSource