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.
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 😁
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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 😁