-
Notifications
You must be signed in to change notification settings - Fork 5
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
Can't use ring channel
in async context: NonNull<ControlBlock> is not
Send`
#69
Comments
Hey, glad you find it useful! It might actually be safe to implement |
Right, the way I'm using it Example for what I'm trying to: use futures::prelude::*;
use futures::sink::SinkExt;
use ring_channel::*;
use std::num::NonZeroUsize;
#[derive(Clone)]
struct A {
backend: RingSender<()>,
}
impl A {
fn new() -> Self {
let (tx, rx) = ring_channel(NonZeroUsize::new(1).unwrap());
async_std::task::spawn(async move {
background_consumer(rx).await;
});
Self { backend: tx }
}
async fn push(&self, t: ()) -> Result<(), ()> {
let mut backend = self.backend.clone();
SinkExt::send(&mut backend, t).await.map_err(|_e| ())
}
}
#[async_std::main]
async fn main() {
let a = A::new();
let a_rc = a.clone();
async_std::task::spawn(async move {
let _ = a_rc.push(()).await.unwrap();
});
loop {}
}
async fn background_consumer(mut consumer: RingReceiver<()>) {
loop {
let msg = consumer.next().await;
println!("{:?}", msg);
}
} |
I'm trying to use |
Hey @loafofpiecrust, thanks for bringing my attention back to this issue! I'll have a look at this over the weekend. |
I haven't forgotten about this issue, just haven't managed to find the time to work on it yet, but it's still at the top of my backlog. |
@brunocodutra Thanks for the follow-up. I've been using my fork with a change based on what's linked earlier in this thread, using atomics. Here's my branch, though I'm not sure if it's the perfect approach. Should I make a PR? |
This reverts commit 972691acdb3200df8a9ef9b0d687357e7cb5535f972691 and closes #69.
@loafofpiecrust it's actually safe to impl |
@niklasad1 & @loafofpiecrust I'm sorry it took so long, but I've just published v0.10 to solve this issue, please check it out when you have the chance and reopen this issue in case you still face problems with this use-case. |
Hey, thanks for this crate.
However, I'm trying to use
ring channel
where it's spawned in a background thread and when I try to spawn futures on I get:Is it reasonable to replace
NonNull
withAtomicPointer
?The text was updated successfully, but these errors were encountered: