thread 'main' panicked at 'A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers.'
Hans-Wu-cn opened this issue · comments
hansWu commented
How to solve the panic when using asynchrony? The code is as follows.
`
pub fn get_device(services: &[Uuid]) -> (Vec, Device) {
let rt = Runtime::new().unwrap();
let future = async {
let adapter = Adapter::default().await.unwrap();
adapter.wait_available().await.unwrap();
info!("looking for device");
let device = adapter
.discover_devices(services)
.await
.unwrap()
.next()
.await
.ok_or("Failed to discover device")
.unwrap()
.unwrap();
info!(
"found device: {:?} ({:?})",
device.name_async().await.as_deref().unwrap_or("(unknown)"),
device.id()
);
let services = services.clone();
for uuid in services {
UUID_STR_VEC.write().await.push(uuid.to_string());
}
(UUID_STR_VEC.read().await.to_vec(), device)
};
rt.block_on(future)
}
`
Nikolay Kim commented
do you use tokio timer?
hansWu commented
你使用东京定时器吗?
yes,i used there
Nikolay Kim commented
fixed in #188
Nikolay Kim commented
include Tokio dependency with "time" feature enabled