Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我按照Rails 参考将一些数据流式传输到客户端。
既然我到处都看到了 Sleep 的使用,那么 Sleep 是否必要?Rails 是否在内部使用 Sleep in Live 来流式传输数据?
Rails 中的sleep函数用于提供指定时间长度的延迟。在列出的情况下,它看起来像是sleep 1在循环中的每次迭代后提供一个短暂的暂停(大约一秒),如下
sleep
sleep 1
response.stream.write "hello world\n"
所以这不是完全必要的,但它将有助于在更平滑的时间范围内间隔输出,而不是一次输出全部批次。