tide
tide copied to clipboard
Conditional Server Sent Events
Question
Is it possible to maintain some state in an SseEndpoint
and use it to conditionally send events?
Additional context
In a side project I need to watch a file on the server and send an update to the client when the file changes.
Ideally the server would check the file periodically and only send an event if the file changed, but I can't figure out how to keep track of the previous state of the file in the SSE endpoint. I tried reading the implementation of the SseEndpoint
but wasn't able to understand it well enough to figure out if what I'd like to do is possible. As a result, right now the client is receiving events and checking if a change occurred.
If it is possible I would be happy to contribute some documentation describing that use case.
I think you'd probably want to spawn a task with async_std::task::spawn
that watches the file, put a cloneable channel of some sort into your app state (maybe a broadcaster, depending on your fan-out needs), move a clone of that into your sse handler, and communicate that way. It's not particularly ergonomic currently, but the longer-term goal is tide channels