Skip to content

Async rework WIP #803

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

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

dangerdyke
Copy link
Contributor

Refactor of the interface code to work better with async code in library consumers, starting with separating the connection logic to a new class, as discussed with @ianmcorvidae on discord.

At this moment, this is only a first draft for the new MeshConnection class.

@CLAassistant
Copy link

CLAassistant commented Jul 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@ianmcorvidae ianmcorvidae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously not complete yet, but basically looks reasonable to me. I know you have further work planned around reworking the way the async code works, which I assume touches more than just the connections, so some of it will fall into how that integration works.

Which is all a lot of words for "looks good, keep going" I guess, haha

Comment on lines 82 to 84
async def listen(self) -> AsyncGenerator[FromRadio]:
while not self.on_disconnect.is_set():
yield await self.recv()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you anticipate this being used in the interface class that would wrap this? Obviously this plus send is basically the core API here. In the existing API, we're of course not really expecting callers to set up threads or such themselves, just set up listeners and make an interface, and otherwise go about their business. Part of why I ask is that we also do various management like updating the in-memory node data, and presumably we'd still want that to happen. Would this then only really be async-iterated-over by the interface class, or would it be used by clients directly?

Either way we should probably document it, anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured the listen function would be used by the MeshInterface to grab every mesh message, and dispatch pubsub events and such appropriately. I haven't quite worked out the specifics but you're right that it would be problematic to have more then one listen call per connection instance, as implemented.

I think what i'm gonna do is just put a lock on the listen method. Clients using the MeshInterface API won't need to even touch Connection instances directly anyways. I can also document everything before everything's ready to be merged.

Comment on lines 178 to 180
for port in serial.tools.list_ports.comports():
if port.hwid != "n/a":
yield port.device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presuming this is planned to eventually flesh out to something similar to what we do in meshtastic.util.findPorts and this is effectively a stub for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, yes. I think it's more sensible to define this behavior alongside the rest of the connection code. I also intend to use this method to implement bluetooth scanning when i get to the BLE connection impl

@dangerdyke dangerdyke marked this pull request as draft July 21, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants