rmosolgo
rmosolgo

Reputation: 1874

How to stop streaming from a specific broadcasting in ActionCable?

I'm trying to use ActionCable as a transport for GraphQL queries (graphql-streaming). GraphQL queries are arbitrary requests for data, so rather than having one cable per query, I'd like to have one cable and multiplex queries over that cable. The flow might be like this:

I'm implementing subscription events as streams, so a subscription looks like this:

stream_from(event_name) { evaluate_graphql_and_push } 

But when the user changes pages, I want to keep the channel connected but stop streaming from that event.

Is this possible with ActionCable?

Upvotes: 3

Views: 2447

Answers (1)

kevinhyunilkim
kevinhyunilkim

Reputation: 864

You can call unsubscribe method on the subscription (a.k.a. channel) object.

i.e.,

channel = App.cable.subscriptions.create "ChannelName"

onPageChange = function() {
    channel.unsubscribe()
}

Upvotes: 1

Related Questions