"There is no reactor runnign" on Linux
David-OConnor opened this issue · comments
Describe the bug
When run on Linux, you get this error: there is no reactor running, must be called from the context of a Tokio 1.x runtime
. It works normally without this error on Windows.
Code:
/// Find bluetooth devices, using the Btleplug library. We wrap it's Async API using blocks
/// here, and a thread upstream.
pub fn run() -> Result<Vec<BluetoothData>, Box<dyn Error>> {
let manager = block_on(Manager::new())?;
let adapters = block_on(manager.adapters())?;
let central = adapters
.into_iter()
.next()
.ok_or("No Bluetooth adapters found")?;
block_on(central.start_scan(ScanFilter::default()))?;
// Wait for a bit to discover devices.
std::thread::sleep(Duration::from_millis(RUN_TIME));
// List discovered devices.
let peripherals = block_on(central.peripherals())?;
for periph in peripherals {
// ...
Expected behavior
The program runs and lists bluetooth devices.
Actual behavior
The program crashes with the above error.
Additional context
I am not trying to make my whole program Async Await; just trying to get Bluetooth devices.
btleplug
depends on Tokio to manage background tasks, so you will need to make all calls within the context of a Tokio executor I'm afraid. Some parts of it may work on some platforms without it, but that shouldn't be expected as all the platform implementations depend on Tokio to some extent.
I appreciate the explanation. Ah well.