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

OneshotSender is not Sync #45

Open
JakkuSakura opened this issue May 15, 2024 · 1 comment
Open

OneshotSender is not Sync #45

JakkuSakura opened this issue May 15, 2024 · 1 comment

Comments

@JakkuSakura
Copy link

I have a scenario like this

let table = Arc::new(DashMap::new());
let (tx, rx) = kannal::oneshot_async();
table.insert(1, tx);
tokio::spawn(async move {
    tabl.remove(1).unwrap().send(()).await;
});
rx.await

But I got
error[E0277]: *mut kanal::oneshot::OneshotInternal<()> cannot be shared between threads safely

@silvanshade
Copy link

This is a common issue with oneshot channels in various crates, even though technically some of the time it should be fine for them to impl Sync (since oneshot operations are usually by-value, meaning that self by-reference methods are unusable).

You can usually work around it by just wrapping the oneshot in a Mutex and then unwrapping with Mutex::into_inner at the send invocation site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants