How to manully close an EventStream #2810
-
I am attempeting to close an EventStream![] from the server when a condition is met. I have tryed to return & break to stop it. However, it just restarts. So I am wondering if it is even possible to stop an event stream from the server. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
My understanding is that returning from the The likely solution for you is going to be to send a close event of some kind, indicating to the client that you will not be sending any more events, and they should close the connection. This way the client will not attempt to reconnect. |
Beta Was this translation helpful? Give feedback.
My understanding is that returning from the
EventStream
macro will close the stream once there is no more content to return. Is the client retrying the connection? Checking the MDN page (https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#closing_event_streams), the JSEventSource
will automatically retry the connection if it gets dropped. UsingEventStream!
, anEvent::retry
can be sent to indicate how long the client should wait before attempting to reconnect, although there doesn't appear to be a way to prevent reconnection from the server side.The likely solution for you is going to be to send a close event of some kind, indicating to the clien…