Add clear queue api (#171)

* Add clear queue api

* Minor improvement

* Update changelog

---------

Co-authored-by: Foti Dim <foti@navideck.com>
This commit is contained in:
Rohit Sangwan
2025-07-16 16:06:39 +05:30
committed by GitHub
parent 0f4bae71e1
commit 71e19988a9
4 changed files with 25 additions and 0 deletions
+6
View File
@@ -414,6 +414,12 @@ class UniversalBle {
);
}
/// Clear a queue.
/// Use [BleCommandQueue.globalQueueId] to clear the global queue.
/// To clear the queue of a specific device, use `deviceId` as [id].
/// If no [id] is provided, all queues will be cleared.
static void clearQueue([String? id]) => _bleCommandQueue.clearQueue(id);
/// [receivesAdvertisements] returns true on web if the browser supports receiving advertisements from a certain `deviceId`.
/// The rest of the platforms will always return true.
/// If true, then you will be getting scanResult updates for this device.
+10
View File
@@ -51,4 +51,14 @@ class BleCommandQueue {
_queueMap[id] = queue;
return queue;
}
void clearQueue(String? id) {
if (id == null) {
_queueMap.forEach((k, v) => v.dispose());
_queueMap.clear();
} else {
_queueMap[id]?.dispose();
_queueMap.remove(id);
}
}
}