desync icon indicating copy to clipboard operation
desync copied to clipboard

Panic when mixing future_sync/desync

Open overflowz opened this issue 2 years ago • 0 comments

Hi,

The following code causes panic, saying thread 'desync jobs thread' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'

use desync::Desync;

#[tokio::main]
async fn main() {
    let desync = Desync::new(0);
    
    desync.future_desync(|_| async move {
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    })
    .detach();

    let _ = desync.future_sync(|_| async move {
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    })
    .await;
}

it happens when I call the second sleep inside the future_desync call, any thoughts? :)

EDIT: it does not happen if I use async_std's sleep instead. Would it be better (and safe) for me to use async_std's features instead of tokio ones?

overflowz avatar Mar 05 '23 09:03 overflowz