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

Allow drop of JoinHandle in web #2383

Open
sampaioletti opened this issue Nov 1, 2024 · 2 comments
Open

Allow drop of JoinHandle in web #2383

sampaioletti opened this issue Nov 1, 2024 · 2 comments
Labels
awaiting Waiting for responses, PR, further discussions, upstream release, etc

Comments

@sampaioletti
Copy link

By making the send a panic on fail

(sender.send(output)).unwrap_or_else(|_| panic!("Fail to send output in spawn_local"));

it prevents a scenario where you aren't concerned with the output or the join handle, and is inconsistent with the non-web behavior.

In my case I'm spawning the local to process some messages

#[flutter_rust_bridge::frb]
pub async fn start_processing()->Ctx{
  let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel::<String>();
  flutter_rust_bridge::spawn(async move {
      loop {
          let Some(msg) = rx.recv().await else {
              log::info!("Exiting");
              return;
          };
          log::info!("process msg");
          process(msg).await;
      }
  });
  Ctx{tx}
}

Everything works as expected.

I eventually drop the returned Ctx and am presented with a panic when the spawn returns and attempts to send the output on the channel.

Since I believe the only failure for sending the output would be when the user drops the join handle it would seem reasonable to ignore that error and not panic.

I'd be happy to submit a PR if that is acceptable.

Copy link

welcome bot commented Nov 1, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented Nov 1, 2024

I'd be happy to submit a PR if that is acceptable.

If we align the web behavior to be consistent with non-web behavior, then I guess that change would be quite welcome!

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Nov 5, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants