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

Fix exponential backoff #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.2",
"version": "1.0.3",
"summary": "Persistent network connections, making client/server communication faster.",
"repository": "http://github.com/elm-lang/websocket.git",
"license": "BSD3",
Expand Down
20 changes: 16 additions & 4 deletions src/WebSocket.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ many unique connections to the same endpoint, you need a different library.
import Dict
import Process
import Task exposing (Task)
import Time exposing (Time)
import WebSocket.LowLevel as WS


Expand Down Expand Up @@ -257,10 +256,13 @@ onSelfMsg router selfMsg state =
Nothing ->
Task.succeed state

Just _ ->
Just (Connected _) ->
attemptOpen router 0 name
|> Task.andThen (\pid -> Task.succeed (updateSocket name (Opening 0 pid) state))

Just (Opening n _) ->
retryConnection router n name state

GoodOpen name socket ->
case Dict.get name state.queues of
Nothing ->
Expand All @@ -278,13 +280,23 @@ onSelfMsg router selfMsg state =
Task.succeed state

Just (Opening n _) ->
attemptOpen router (n + 1) name
|> Task.andThen (\pid -> Task.succeed (updateSocket name (Opening (n + 1) pid) state))
retryConnection router n name state

Just (Connected _) ->
Task.succeed state


retryConnection
: Platform.Router msg Msg
-> Int
-> String
-> State msg
-> Task x (State msg)
retryConnection router n name state =
attemptOpen router (n + 1) name
|> Task.andThen (\pid -> Task.succeed (updateSocket name (Opening (n + 1) pid) state))


updateSocket : String -> Connection -> State msg -> State msg
updateSocket name connection state =
{ state | sockets = Dict.insert name connection state.sockets }
Expand Down