Skip to content

Cannot start a runtime from within a runtime #3857

Answered by Darksonn
Osiris9999 asked this question in Q&A
Discussion options

You must be logged in to vote

When you annotate a function with #[tokio::main], that turns the function into this:

fn main() {
    tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            ...
        })
}

So that means that if you call a method annotated with #[tokio::main] from asynchronous code, you are creating a new runtime while being in asynchronous code.

Remove the #[tokio::main] annotation from scape::main.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@brandonros
Comment options

@Darksonn
Comment options

@brandonros
Comment options

@brandonros
Comment options

@Darksonn
Comment options

Answer selected by Osiris9999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants