-
Notifications
You must be signed in to change notification settings - Fork 36
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
API suggestion: clone sender vs. take sender vs. send #77
Comments
That sounds like a solid proposal, thanks for putting all that on writing. I hadn't given a lot of thought about this, and what you suggest makes a lot of sense. I suppose with that we should ensure that sources with a sending end like that should take care of automatically removing themselves from the event loop when then realize their sending end has been destroyed and all pending events have been processed? In any case I'm quite interested with this! |
It's funny you should say that, because I was about to open another issue/suggestion about that. It might help to keep it separate, otherwise I think it might become hard to follow. |
I wrote an essay over in #78 for you. |
I guess I should ask, how would the x11 backend in smithay be brought more in line with this. Currently X11Backend allows you to get X11Handles, effectively acting like the timer sources. https://github.com/Smithay/smithay/blob/master/src/backend/x11/mod.rs |
@i509VCB So firstly, what I'm suggesting is merely a convention for the library, not a trait or anything like that. So in the simplest sense, dependent libraries don't have to change if they don't want to (eg. they don't want to break backwards compatibility, it doesn't suit their architecture). Having said that, if they wanted to follow the convention, it sounds like the use-case you mention would be to just use a |
Ah I see. |
So I've started experimenting a little with that, and I have two things coming to mind I'm not really sure about:
|
Yeah, possibly. I had it that way because, frankly, I tend to I had missed the detail of the |
With #89 this point is becoming weaker given the |
There are a few inconsistencies in Calloop's higher-level event sources, and even though they are extremely minor, I thought I'd make the suggestion since I've coded up an alternative for the event sources I've made for ZeroMQ and USB.
Take for example:
Ping
hasmake_ping()
to construct, which returns a(sender, source)
pair. Using it requires callingping()
on the sender.Channel
haschannel()
(notmake_channel()
!) which returns a(sender, source)
pair. Using it requires callingsend()
on the sender.Timer
hasTimer::new()
. Using it requires getting a handle from theTimer
itself.Both
Ping
andChannel
have handles that close on drop.Timer
does not.This all quickly becomes apparent if you have a composite event source that uses multiple kinds of these, and kind of unwieldy at times. For example, if your composite source has both a ping and a channel for internal reasons, you need four fields to use them.
Here is an API we stabilised on that kind of gives the best of both worlds:
Disadvantages:
Advantages:
self.pinger.ping()
self.channel.take_sender()
instead of needing to keep (a) the sender and (b) an option wrapperOption
(send
/clone_sender
/take_sender
) == (map
/clone
/take
)source::Source::new() -> Result<Source>
instead ofsource::make_source() -> Result<(sender, source)>
make_source()
just becomeslet source = Source::new(); (source.take_sender(), source)
Let me know what you think, and if you're interested I'll code something up for the existing types that have sending handles.
The text was updated successfully, but these errors were encountered: