DEV Community

Discussion on: Building with server-sent events with React and Node.js

Collapse
 
wsh4and profile image
Eko Andri Subarnanto

Hi,

  1. How do you do sse if you want to wait for the long running query to be completed?
  2. How do you close connection if you already receive the completed data?

Thank you for the tutorial, I learned a lot.

Collapse
 
4shub profile image
Shubham Naik

Hi there, sorry for late response!

  1. I am not sure, could you rephrase this question?
  2. you should invoke res.end() when you want to close the connection.

Best,
Shubham

Collapse
 
wsh4and profile image
Eko Andri Subarnanto

Hi Shubham, thank you for your reply

  1. Let's say that I want to perform a long running query in the backend, and I want to inform the UI the percentage of how much it is done, say 10%, 20% and so on. Is it through a sse connection or with something else? So the backend keeps sending the 'value' of how much the query has been done? And which part close the connection, UI atau backend?
  2. Thank you.

Regards,
Andri

Thread Thread
 
4shub profile image
Shubham Naik

You could use an SSE connection for this yes, and then you could close the connection when value = 100?

Thread Thread
 
wsh4and profile image
Eko Andri Subarnanto

Oh I see, yes thank you for your reply