Skip to content

Bug: task::block_on cannot run on an async context #798

Closed
@rakshith-ravi

Description

@rakshith-ravi

I have the following code:

// I don't control these parts. They come from a library:
async fn run() {
    while let Some(data) = receiver.next().await {
        process_data(data);
    }
}

// This is the part that I get to control
fn process_data(data: Vec<u8>) {
    // I need to run an async task here.
    // So I do this:
    task::block_on(async {
        do_something_async_here().await;
    });
}

The process_data function crashes with the following error:

thread 'async-std/runtime' panicked at 'cannot run an executor inside another executor', <::std::macros::panic macros>:2:4

I think it might have to do with the switch to smol, since I didn't face this issue earlier with 1.5. This happens only on 1.6. Please advice me on how to proceed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions