Skip to content

Instantly share code, notes, and snippets.

@stevschmid
Created March 6, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevschmid/e2c8b9474535c1085c8a56ddad2276a2 to your computer and use it in GitHub Desktop.
Save stevschmid/e2c8b9474535c1085c8a56ddad2276a2 to your computer and use it in GitHub Desktop.
import consumer from "./consumer"
let subscription
const unsubscribe = () => {
console.log('unsubscribe')
subscription.unsubscribe()
}
const DELAY_RESUBSCRIBE = 10
const subscribe = () => {
console.log('subscribe')
subscription = consumer.subscriptions.create("TestChannel", {
connected() {
// Called when the subscription is ready for use on the server
console.log('connected')
setTimeout(() => {
unsubscribe()
setTimeout(() => subscribe(), DELAY_RESUBSCRIBE)
}, 3000)
},
})
}
subscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment