-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add clear_peripherals method to adapter #382
base: dev
Are you sure you want to change the base?
Conversation
@@ -355,6 +355,9 @@ pub trait Central: Send + Sync + Clone { | |||
/// Add a [`Peripheral`] from a MAC address without a scan result. Not supported on all Bluetooth systems. | |||
async fn add_peripheral(&self, address: &PeripheralId) -> Result<Self::Peripheral>; | |||
|
|||
/// Clear the list of [`Peripheral`]s that have been discovered so far. | |||
async fn clear_peripherals(&self) -> Result<()>; |
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.
As far as I can see there's no need for this to be async.
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.
I think it is best to keep it async, so that if a new platform (or even a linux solution later) needs it to be async we don't have to break the API. What do you think?
@@ -101,6 +101,12 @@ impl Central for Adapter { | |||
)) | |||
} | |||
|
|||
async fn clear_peripherals(&self) -> Result<()> { | |||
Err(Error::NotSupported( |
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.
I'm worried that this will result in people writing programs that crash on Linux as they only tested it on other platforms. What do you think about this just being a silent no-op on Linux? Not being able to clear the peripheral list shouldn't be a big issue in most cases I can think of.
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.
That sounds good, I'll change it. It may be possible to clear the bluez list, but the bluez-async lib doesn't seem to currently support it.
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.
Making this as changes requested since there was some talk of updates but they haven't happened yet.
Add clear_peripherals method to adapter, so that the peripheral list can be cleared after being used.
Without this, the list would keep growing until the whole adapter object is dropped.
The method returns a result so that later if a platform/functionality needs to be fallible the API won't need to be changed.
AFAIK, Linux doesn't support this as the peripheral list comes from bluez directly.
Solves #206