Skip to content
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

Tokio/futures async support #33

Open
rubdos opened this issue Mar 31, 2018 · 18 comments
Open

Tokio/futures async support #33

rubdos opened this issue Mar 31, 2018 · 18 comments
Labels

Comments

@rubdos
Copy link

rubdos commented Mar 31, 2018

As suggested in #32:

I've been experimenting with porting dbus-tokio to futures 0.2.0, and it seems like its dependency on tokio will get a lot lighter (seems like only tokio-reactor will be needed). I suggest that whenever tokio releases their futures 0.2 support, we start implementing this. For now, we can discuss a bit how the interface should look like.

One of the things I think would be extremely cool, would be the possibility to "subscribe" to new players coming online. With the current interface, you basically have to query dbus on set intervals for active players. Having something like PlayerFinder::stream() -> impl Stream<StreamItem=Player> would be very cool.

Secondly, having a Player somehow emit events in form of a Stream would be very useful too.

@Mange
Copy link
Owner

Mange commented Mar 31, 2018

I really like the idea of streaming players.

I also like the plan to wait for 0.2. I'm excited!

@rubdos
Copy link
Author

rubdos commented Mar 31, 2018

I also like the plan to wait for 0.2. I'm excited!

Cool. I'll probably catch the guys at dbus-rs somewhere next week, give them the port for 0.2 I was working on.

@rubdos
Copy link
Author

rubdos commented Apr 1, 2018

FYI, I've dropped my (non working) futures 0.2 code over at dbus-rs diwic/dbus-rs#129

@Mange
Copy link
Owner

Mange commented Apr 8, 2018

FYI 0.2 just shipped, but it seems like it's only meant for experimentation still.

I consider 0.2 a "snapshot" that's good for experimentation but shouldn't be used heavily, since stable 0.3 should be coming in a couple of months or less.

@rubdos
Copy link
Author

rubdos commented Apr 10, 2018

FYI 0.2 just shipped, but it seems like it's only meant for experimentation still.

Yeh, I read that too. Thing is, we have to await! Tokio first, because their support is still quite alpha-ish :-)

@Mange Mange added the Feature label Apr 16, 2018
@ischeinkman
Copy link
Contributor

Would it make more sense to use tokio + dbus's nonblocking support, or to just roll a custom version via callbacks? The second would likely be much easier since it would reuse most of the existing code and also be executor-independent.

@Mange
Copy link
Owner

Mange commented Feb 19, 2020

I honestly don't know. I'm not well versed in these ecosystems yet.

@rubdos
Copy link
Author

rubdos commented Feb 20, 2020

or to just roll a custom version via callbacks? The second would likely be much easier since it would reuse most of the existing code and also be executor-independent.

That would not at all integrate in any ecosystem. Callbacks could be useful, but are not an alternative to async-await integration.

@ischeinkman
Copy link
Contributor

Oh I meant using custom futures implemented via having callbacks update a response value and then waking the waiting future.
I've actually started implementing one based mostly on dbus::nonblock, but there were still some places I needed to do the custom future approach -- the biggest being the fact that there is currently no send_with_reply_async available, so I had to roll my own.

@rubdos
Copy link
Author

rubdos commented Feb 22, 2020

Oh I meant using custom futures implemented via having callbacks update a response value and then waking the waiting future.

Can't you use channels for that?

I've actually started implementing one based mostly on dbus::nonblock, but there were still some places I needed to do the custom future approach -- the biggest being the fact that there is currently no send_with_reply_async available, so I had to roll my own.

I wonder what dbus-tokio does then, can't you base of that? I just might not have enough knowledge of the internals of tokio et al. though.

@th1j5
Copy link

th1j5 commented Feb 11, 2021

Hey, how is this issue going? Tokio is now version 1.2.0, so maybe it is stable enough to have a look at it again?

I'm asking this because:
I'm using mpris::PlayerEvents to count how many tracks have been played by matching on Event::TrackChanged(_). In the meantime, I'd also like to control the sound etc., but because PlayerEvents is a blocking iterator, the whole (OS-)thread is blocked, and I think it is a bit expensive to need a whole thread just for counting tracks...

I'm probably not qualified to help with this work, quite new to Rust... :/

(Thank you for the library, it's just what I need! I first thought I had to interact with C calls to control Rhythmbox *shiver*, then I discovered D-BUS and now this)

@Mange
Copy link
Owner

Mange commented Feb 11, 2021

Booting up a thread that just blocks is not very expensive at all afaik, it's how everyone did it before we got async io after all.

It might be time to look into it now, but then again it's very hard to support both async and sync io in the same codebase in Rust from what I can tell. Async tends to take over everything and infecting stuff. Async also adds a huge amount of overhead (a whole runtime) and I've heard that the dbus infrastructure works badly with async io because of assumptions (like with OpenGL and multi-threading), but that could be a big misunderstanding from my part.

If anyone can come up with a design that allows compile-time toggle of async support (I don't mind if it's default or not), that also allows you to plug in different runtimes (tokio, async-std, etc.), then I would be happy to get it in right now!

@th1j5
Copy link

th1j5 commented Feb 11, 2021

Ok, then I'll just use something like std::thread::spawn. Not that it matters very badly...

I do know that some crates use options in their Cargo.toml to mark what you want to use. (e.g. clap = {version = "~2.33.3", features = ["yaml"]} or tokio = { version = "1", features = ["full"] })
So I could imagine a mpris = {version = "2", features = ["async"]}

But I probably can't help further

@Mange
Copy link
Owner

Mange commented Feb 11, 2021

Ha ha, no worries! 🙂

Yeah, that's what I want, without the code becoming too complex to support it. Maybe I'll look into an experimental implementation some day.

@GioPan04
Copy link

GioPan04 commented May 1, 2023

Any update on this?

@Mange
Copy link
Owner

Mange commented May 2, 2023

No. I've not worked on this project at all since last time.

@Techno3d
Copy link

Techno3d commented Aug 29, 2023

I've been working on an async version (ig async wrapper) for this library called mpris-async-rs. It technically is just running another thread that tracks changes and then sends that to a streamer class. It is a little buggy (especially if you disconnect a player and then reopen it, where it crashes) so I haven't put it on crates or anything. I thought I'd mention it here since it seems some people want the feature.

I do want to mention that async code that spawns a task can be slightly annoying to code since Player does not implement send (I think because of the Rc<PooledConnection>?)

@Mange
Copy link
Owner

Mange commented Aug 30, 2023

I have my own local rewrite that I work on a few hours per year, but that version is async using zbus.

If people are interested in helping out, I could publish the branch and accept PRs on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants