DEV Community

Discussion on: Server Sent Events with Saturn and F#

Collapse
 
sirseanofloxley profile image
Sean Allin Newell

I feel like there's a better way to keep a reference to the response to write and flush to rather than doing a while true loop, especially in that file watcher example.

Collapse
 
tunaxor profile image
Angel Daniel Munoz Gonzalez • Edited

The connection needs to be open until the client disconnects from the SSE endpoint, the while true is just a very simple way to keep it alive, I don't expect my clients to "send" a disconnect signal of some sorts in this example, I expect them to close the page and I'd just dispose my resources on the aborted event.

If you're looking for something more robust/complex: Lib.AspNetCore.ServerSentEvents uses a pending task until the client signals a disconnection as you can see here.

In any case, Yes there are better ways, I just wanted to share that server sent events are a pretty simple concept (which I previously thought it wasn't), just do an http request and receive information from the server 😁