ntex-rs / ntex

framework for composable networking services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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)

}
`

do you use tokio timer?

你使用东京定时器吗?

yes,i used there

fixed in #188

include Tokio dependency with "time" feature enabled