-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove IO.select #4392
Remove IO.select #4392
Conversation
IO.select frequently confuses users by blocking all fibers, and can easily be replaced by blocking CSP programs.
I've bitten a few time by this too. It's confusing and hard to explain to newcomers 😭 |
And above all unneeded with how Crystal works (non blocking, event loop, etc..) |
Granted. This is long held legacy from before IO got evented. We now use better techniques (eg: epoll, kpoll) to automatically switch contexts as required. Anybody coming here and lacking support for def server_loop(server)
loop do
spawn handle_client(server.accept)
end
end
spawn do
TCPServer.open(9292) { |server| server_loop(server) }
end
spawn do
UNIXServer.open("/tmp/app.sock") { |server| server_loop(server) }
end
sleep |
Does the above apply to one object shared between fibers? For example, say I have a require "socket"
sock = TCPSocket.new "example.org", 80
spawn do
sock << "request\n"
end
spawn do
while true
puts sock.gets
end
end
sleep |
Yes, that should be perfectly fine as long as reading and writing are clearly separated. |
All right, thanks for the clarification. Crystal really makes this kind of things easy. By the way, it took me some time to find this thread when searching for the answer. Would it be possible to add this information into the official documentation? It might be helpful to some. |
I create a new thread in form for discuss more deeper real-life use cases for convert IO.select into fiber https://forum.crystal-lang.org/t/need-document-for-how-porting-io-select-in-ruby-crystal/5374 |
This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/need-document-for-how-porting-io-select-in-ruby-crystal/5374/7 |
IO.select frequently confuses users by blocking all fibers, and can easily be replaced by blocking CSP programs.