I followed the Rails reference to stream some data to the client.
Is the Sleep necessary since I have seen the usage of Sleep everywhere? Does Rails internally use Sleep in Live to stream data?
I followed the Rails reference to stream some data to the client.
Is the Sleep necessary since I have seen the usage of Sleep everywhere? Does Rails internally use Sleep in Live to stream data?
The sleep
function in Rails is used to provide a delay of a specified length of time. In the case listed it looks like sleep 1
is providing a short pause (roughly one second) after each iteration in your loop, following
response.stream.write "hello world\n"
So it's not exactly necessary, but it will serve to space the output across a smoother time-frame, rather than having the whole lot output at once.