Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Multiple open connections when subscription changes quickly #23

Open
Keyamoon opened this issue Jun 18, 2017 · 1 comment
Open

Multiple open connections when subscription changes quickly #23

Keyamoon opened this issue Jun 18, 2017 · 1 comment

Comments

@Keyamoon
Copy link

Keyamoon commented Jun 18, 2017

To reproduce this issue, try the SSCCE that follows and double click on the Toggle button a couple of times. You should see multiple open/pending connections in Chrome's Network tab. If you allow some delay between clicks, connections get closed properly.

I have tried this on macOS version 10.12.5 using Chrome version 58.0.3029.110 and Chrome Canary version 61.0.3132.0.

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import WebSocket


main =
  Html.program
    { init = init
    , view = view
    , update = update
    , subscriptions = subscriptions
    }


echoServer : String
echoServer =
  "wss://echo.websocket.org"


type alias Model = Bool


init : (Model, Cmd Msg)
init =
  (True, Cmd.none)


type Msg
  = NewMessage String
  | Toggle


update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    Toggle ->
      (not model, Cmd.none)
    _ ->
      (model, Cmd.none)


subscriptions : Model -> Sub Msg
subscriptions model =
  if model
     then WebSocket.listen echoServer NewMessage
     else Sub.none


view : Model -> Html Msg
view model =
  div [] [ button [onClick Toggle] [text "Toggle"] ]
@process-bot
Copy link

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants