Git Product home page Git Product logo

Comments (4)

benwilson512 avatar benwilson512 commented on June 1, 2024 1

@michaelcaterisano Depending on what you are doing with those channel pids you could send them a message and then do it in a handle_info. Otherwise the solution you have seems fine to me.

from absinthe.

michaelcaterisano avatar michaelcaterisano commented on June 1, 2024

I ended up getting this to work by adding a handle_out function to absinthe_phoenix and sending an unsubscribe message directly to the channel. Is there a better way to handle this?

  def handle_out("unsubscribe", %{"subscriptionId" => doc_id}, socket) do
    pubsub =
      socket.assigns
      |> Map.get(:absinthe, %{})
      |> Map.get(:opts, [])
      |> Keyword.get(:context, %{})
      |> Map.get(:pubsub, socket.endpoint)

    Phoenix.PubSub.unsubscribe(socket.pubsub_server, doc_id)
    Absinthe.Subscription.unsubscribe(pubsub, doc_id)
    {:noreply, socket}
  end
sub_id = "some-sub-id-i-grabbed" 

broadcast = %Phoenix.Socket.Broadcast{
      topic: "__absinthe__:control",
      event: "unsubscribe",
      payload: %{"subscriptionId" => sub_id}
    }

Phoenix.PubSub.broadcast!(My.PubSub, "__absinthe__:control", broadcast)

from absinthe.

benwilson512 avatar benwilson512 commented on June 1, 2024

Hey @michaelcaterisano which process is calling unsubscribe? The caller of unsuscribe needs to be the process that also called subscribe, it can't be done from a different process.

from absinthe.

michaelcaterisano avatar michaelcaterisano commented on June 1, 2024

@benwilson512 I figured that was the case. I was definitely trying to call unsubscribe from a different process than subscribe. Do you have thoughts about the workaround above? Is there a better way to unsubscribe individual subscriptionIds?

from absinthe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.