flutter_rust_bridge icon indicating copy to clipboard operation
flutter_rust_bridge copied to clipboard

spawn works as not expected

Open NightBlaze opened this issue 1 year ago • 3 comments

Describe the bug

Still new to Rust so it's look like a bug in a wrapper of spawn.

In general Rust code I can write:

#[tokio::main]
async fn main() {
    let string = String::from("");
    tokio::spawn(async move {
        println!("{}", string);
        tokio::spawn(async move {
            println!("{}", string);
        });
    });
}

and it works as expected.

If I tried to write similar code in frb:

pub async fn foo() {
    let string = String::from("");
    flutter_rust_bridge::spawn(async move {
        // println!("{}", string); // Even if this line is commented
        flutter_rust_bridge::spawn(async move {
            println!("{}", string);
        });
    });
}

then I have an error use of moved value: "string" which is seems weird because I just move string to the second spawn's closure.

Steps to reproduce

pub async fn foo() {
    let string = String::from("");
    flutter_rust_bridge::spawn(async move {
        // println!("{}", string); // Even if this line is commented
        flutter_rust_bridge::spawn(async move {
            println!("{}", string);
        });
    });
}

Logs

-

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

was 2.0.0-dev.24, updated to 2.0.0-dev.28 but idk did I it correct or not

Flutter info

No response

Version of clang++

No response

Additional context

No response

NightBlaze avatar Mar 12 '24 14:03 NightBlaze

Hmm interesting. frb's spawn

    fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        self.0.spawn(future)
    }

calls tokio's spawn:

    pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
    where
        F: Future + Send + 'static,
        F::Output: Send + 'static,
    {
        ...
    }

A quick look does not reveal any differences... Indeed if there is any difference, we cannot write down self.0.spawn at all

Thus, could you please paste full error logs etc?

fzyzcjy avatar Mar 12 '24 14:03 fzyzcjy

Found an issue. It's on my side. Sorry.

NightBlaze avatar Mar 12 '24 17:03 NightBlaze

It's OK!

fzyzcjy avatar Mar 12 '24 23:03 fzyzcjy

Close since this seems to be solved. Feel free to reopen if having any issues!

fzyzcjy avatar May 15 '24 09:05 fzyzcjy

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

github-actions[bot] avatar May 29 '24 10:05 github-actions[bot]