Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: async frb(init) #2474

Open
mcmah309 opened this issue Jan 2, 2025 · 3 comments
Open

Bug: async frb(init) #2474

mcmah309 opened this issue Jan 2, 2025 · 3 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working

Comments

@mcmah309
Copy link
Contributor

mcmah309 commented Jan 2, 2025

Describe the bug

Looking at the docs https://cjycode.com/flutter_rust_bridge/guides/how-to/init#use-frbinit , it is not clear when an init function will be called. I assume it is called by await RustLib.init(). Indeed this code does throw on the dart side with RustLib.init().

#[flutter_rust_bridge::frb(init)]
pub fn on_rust_lib_init() {
   panic!("panic at init");
}

But making the function async, does not result in a thrown exception on the dart side.

#[flutter_rust_bridge::frb(init)]
pub async fn on_rust_lib_init() {
   panic!("panic at init");
}

I would expect await RustLib.init() to throw here.

@mcmah309 mcmah309 added the bug Something isn't working label Jan 2, 2025
@mcmah309 mcmah309 changed the title Possible FRB init Bug Bug: async RustLib.init Jan 2, 2025
@mcmah309 mcmah309 changed the title Bug: async RustLib.init Bug: async frb(init) Jan 2, 2025
@mcmah309
Copy link
Contributor Author

mcmah309 commented Jan 2, 2025

Indeed it looks like any code inside pub async fn on_rust_lib_init() is not called.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 2, 2025

Indeed it looks like any code inside pub async fn on_rust_lib_init() is not called.

Hmm if so it is a bug... It should be called. I will check this soon.

At the same time, a workaround is make it non "init" and manually call it.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Jan 3, 2025

Btw, have you run codegen after changing code?

EDIT: Seems I cannot reproduce it. Details:

https://github.com/fzyzcjy/flutter_rust_bridge/blob/feat/12702/frb_example/dart_minimal/rust/src/api/minimal.rs

  1. If do pub async fn init_app, see error logs like thread 'tokio-runtime-worker' panicked at src/api/minimal.rs:3:1:, showing it is executed, and it executed by tokio (async runtime)
  2. If do pub fn init_app, see error logs like thread '<unnamed>' panicked at src/api/minimal.rs:3:1:, showing it is also executed

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants