Skip to content

Commit

Permalink
Clarified forever in websocket docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Oct 27, 2021
1 parent d8872b3 commit 32a0622
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Guide/websockets.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ You can see that we can access the state using [`state <- getState`](https://ihp

Now whenever the connection is closed, it will print out the message inside the terminal where the IHP server is running.

**Good to know:** The connection is automatically closed when the [`run`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:run) function has finished. Therefore it's normal that the `... has left!` message is directly printed after you entered the name. To keep it running until the browser windows is closed, add a [`forever receiveDataMessage`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:receiveDataMessage) to the end of the [`run`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:run).
**Good to know:** The connection is automatically closed when the [`run`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:run) function has finished. Therefore it's normal that the `... has left!` message is directly printed after you entered the name. To keep it running until the browser windows is closed, add a `forever` to the the [`run`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:run):

```haskell
run = do
-- Loops until the connection is closed
forever do
name <- receiveData @Text
setState NameEntered { name }
sendTextData ("Hello " <> name <> "!")
```

As you've seen above the primitive state operations are [`setState`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:setState) and [`getState`](https://ihp.digitallyinduced.com/api-docs/IHP-WebSocket.html#v:getState). Using these two operations together with a good data structure is a very powerful way to manage your stateful WebSocket connections.

Expand Down

0 comments on commit 32a0622

Please sign in to comment.