aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2015-10-14 17:09:10 -0500
committerJavan Makhmali <javan@javan.us>2015-10-14 17:09:10 -0500
commite8e6937d96f969c16011f3e1f136d6b8c21f8c97 (patch)
treea47590cf42eb2c3a5d16ee4aee937531e07d69fc
parente07972711ed9e9404d4e6051c1ad23275a6d6645 (diff)
downloadrails-e8e6937d96f969c16011f3e1f136d6b8c21f8c97.tar.gz
rails-e8e6937d96f969c16011f3e1f136d6b8c21f8c97.tar.bz2
rails-e8e6937d96f969c16011f3e1f136d6b8c21f8c97.zip
Add delay before reopening
-rw-r--r--lib/assets/javascripts/cable/connection.coffee11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/assets/javascripts/cable/connection.coffee b/lib/assets/javascripts/cable/connection.coffee
index 8256f731c5..801b3d97b1 100644
--- a/lib/assets/javascripts/cable/connection.coffee
+++ b/lib/assets/javascripts/cable/connection.coffee
@@ -1,5 +1,7 @@
# Encapsulate the cable connection held by the consumer. This is an internal class not intended for direct user manipulation.
class Cable.Connection
+ @reopenDelay: 500
+
constructor: (@consumer) ->
@open()
@@ -22,8 +24,13 @@ class Cable.Connection
@webSocket?.close()
reopen: ->
- @close()
- @open()
+ if @isState("closed")
+ @open()
+ else
+ try
+ @close()
+ finally
+ setTimeout(@open, @constructor.reopenDelay)
isOpen: ->
@isState("open")