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

Subscription with MPSC receiver in context data #1495

Open
PainOchoco opened this issue Mar 17, 2024 · 0 comments
Open

Subscription with MPSC receiver in context data #1495

PainOchoco opened this issue Mar 17, 2024 · 0 comments
Labels
question Further information is requested

Comments

@PainOchoco
Copy link

Hello there,

I'm trying to make a subscription with a MPSC channel by passing the channel's receiver in async_graphql's context data.
However, the ctx.data only provides reference to objects, how could I get the rx receiver directly?

Here's a small example:

use async_graphql::{self, Context, Subscription};
use futures::{channel::mpsc::Receiver, stream::Stream};

#[derive(Default)]
pub struct SomeSubscription;

#[Subscription]
impl SomeSubscription {
    async fn something(&self, ctx: &Context<'_>) -> impl Stream<Item = i32> {
        let rx = ctx.data::<Receiver<i32>>().unwrap();
        // rx is a &Receiver<i32>, what to do?!
    }
}

Is there another way to do this?
Please let me know how should i go about that!

@PainOchoco PainOchoco added the question Further information is requested label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant