Skip to content

Commit

Permalink
Allow pure Ruby and Java NIO::Selector to be initialized with nil
Browse files Browse the repository at this point in the history
Trying to make this consistent across all backends. Passing nil was only
working with libev.
  • Loading branch information
jcmfernandes authored and ioquatix committed Jan 5, 2021
1 parent 17155b9 commit 4111b1c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/nio4r/org/nio4r/Selector.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IRubyObject initialize(ThreadContext context) {

@JRubyMethod
public IRubyObject initialize(ThreadContext context, IRubyObject backend) {
if(backend != context.runtime.newSymbol("java")) {
if(backend != context.runtime.newSymbol("java") && !backend.isNil()) {
throw context.runtime.newArgumentError(":java is the only supported backend");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/nio/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.backends

# Create a new NIO::Selector
def initialize(backend = :ruby)
raise ArgumentError, "unsupported backend: #{backend}" unless backend == :ruby
raise ArgumentError, "unsupported backend: #{backend}" unless [:ruby, nil].include?(backend)

@selectables = {}
@lock = Mutex.new
Expand Down
4 changes: 4 additions & 0 deletions spec/nio/selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
example.reporter.message "Supported backends: #{described_class.backends}"
end

it "automatically selects a backend if none or nil is specified" do
expect(described_class.new.backend).to eq described_class.new(nil).backend
end

it "raises ArgumentError if given an invalid backend" do
expect { described_class.new(:derp) }.to raise_error ArgumentError
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

config.filter_run_when_matching :focus

config.expect_with :rspec do |c|
c.syntax = :expect
end
Expand Down

0 comments on commit 4111b1c

Please sign in to comment.