Skip to content

Commit

Permalink
Fix exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
bgourlie committed Feb 12, 2017
1 parent 534ba2c commit f31bf69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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

0 comments on commit f31bf69

Please sign in to comment.