socketry / nio4r

Cross-platform asynchronous I/O primitives for scalable network clients and servers.
Other
967 stars 86 forks source link

Allow pure Ruby and Java NIO::Selector to be initialized with nil #258

Closed jcmfernandes closed 3 years ago

jcmfernandes commented 3 years ago
jcmfernandes@jcmfernandes-desktop:~/own_devel/nio4r^nil-auto-select-backend ♥
% irb                                                                                21-01-04 - 19:45:34
irb(main):001:0> require 'nio'
=> true
irb(main):002:0> NIO::Selector.new(nil)
=> #<NIO::Selector:0x0000555cdc6c88e0>
irb(main):003:0>
jcmfernandes@jcmfernandes-desktop:~/own_devel/nio4r^nil-auto-select-backend ♥
% env NIO4R_PURE=true irb                                                            21-01-04 - 19:45:49
irb(main):001:0> require 'nio'
=> true
irb(main):002:0> NIO::Selector.new(nil)
Traceback (most recent call last):
        6: from /home/jcmfernandes/.asdf/installs/ruby/2.7.2/bin/irb:23:in `<main>'
        5: from /home/jcmfernandes/.asdf/installs/ruby/2.7.2/bin/irb:23:in `load'
        4: from /home/jcmfernandes/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        3: from (irb):2
        2: from (irb):2:in `new'
        1: from /home/jcmfernandes/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/nio4r-2.5.4/lib/nio/selector.rb:17:in `initialize'
ArgumentError (unsupported backend: )

Trying to make this consistent across all backends. Passing nil was only working with libev.

I thought about introducing :auto as an explicit way to say "select the best", but at the end of the day that's what nil is already doing. Feedback is welcome! :smile_cat:

Types of Changes

Testing

ioquatix commented 3 years ago

Thanks, this seems like a good improvement to me.