Skip to content

Commit

Permalink
Fix reconnect test
Browse files Browse the repository at this point in the history
Regression from commit fd6d5b0.
  • Loading branch information
lydell committed Jan 6, 2025
1 parent 43bfabe commit 9210e2b
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,21 +1330,27 @@ function update(msg: Msg, model: Model): [Model, Array<Cmd>] {
case "UiMsg":
return onUiMsg(msg.date, msg.msg, model);

case "WebSocketClosed": {
const attemptNumber =
"attemptNumber" in model.status ? model.status.attemptNumber + 1 : 1;
return [
{
...model,
status: {
tag: "SleepingBeforeReconnect",
date: msg.date,
attemptNumber,
case "WebSocketClosed":
// This message is triggered from both the WebSocket "error" and "closed" events.
// Sometimes, both events happen at the same time. We only want to start reconnecting once,
// so check if we’re already sleeping before doing anything.
if (model.status.tag === "SleepingBeforeReconnect") {
return [model, []];
} else {
const attemptNumber =
"attemptNumber" in model.status ? model.status.attemptNumber + 1 : 1;
return [
{
...model,
status: {
tag: "SleepingBeforeReconnect",
date: msg.date,
attemptNumber,
},
},
},
[{ tag: "SleepBeforeReconnect", attemptNumber }],
];
}
[{ tag: "SleepBeforeReconnect", attemptNumber }],
];
}

case "WebSocketConnected":
return [
Expand Down

0 comments on commit 9210e2b

Please sign in to comment.