#Tauri running async code from main()

7 messages · Page 1 of 1 (latest)

jade sentinel
#

I am in the process of incorporating Tauri into my program. Currently, I have a async main function which calls many other async functions inside of it. I'm using #[tokio::main] for this.

I'm experiencing an issue with starting a runtime within a runtime. I think this is because Tauri also creates a runtime then Tokio tries to create another.

I have no idea what to do, and everything I try to do does not seem to solve the issue.

#

Currently my code looks something like this,


#[tauri::command(async)] 
fn test(password: String) {
    main();
}

#[tokio::main]
pub async fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![greet, test])
        .run(tauri::generate_context!())
       .expect("error while running tauri application");    
    //
    // function calling await below...
true thicket
#

Tauri creates a Tokio runtime. You shouldn't make an async main function. You should launch async tasks inside the .setup function

jade sentinel
#

how should I name it?

true thicket
coarse kelp
#

that could also mean you use pub on the command while it's defined in your main.rs/lib.rs file. If it's in the same file as the tauri Builder you'll have to remove the pub keyword, alternatively you can move the command in another module.