Skip to content

Commit

Permalink
Moved Thread/EventMachine creation inside of #run.
Browse files Browse the repository at this point in the history
This cleans up the API a bit by removing the requirement of placing #run
inside a Thread.new {EventMachine.next_tick {}} block. That should not
be the caller's responsibility.
  • Loading branch information
soh-cah-toa committed Apr 25, 2014
1 parent 9b3dfac commit 3b3d7fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extensions/dns/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.pre_http_start(http_hook_server)
end
end

Thread.new { EventMachine.next_tick { dns.run(:upstream => servers, :listen => interfaces) } }
dns.run(:upstream => servers, :listen => interfaces)

print_info "DNS Server: #{address}:#{port} (#{protocol})"
print_more upstream_servers
Expand Down
18 changes: 11 additions & 7 deletions extensions/dns/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,19 @@ def remove_ruleset!
# @option options [Array<Array>] :listen local interfaces to listen on
def run(options = {})
@lock.synchronize do
upstream = options[:upstream]
listen = options[:listen]
Thread.new do
EventMachine.next_tick do
upstream = options[:upstream] || nil
listen = options[:listen] || nil

if upstream
resolver = RubyDNS::Resolver.new(upstream)
@otherwise = Proc.new { |t| t.passthrough!(resolver) }
end

unless upstream.nil? || upstream.empty?
resolver = RubyDNS::Resolver.new(upstream)
@otherwise = Proc.new { |t| t.passthrough!(resolver) }
super(:listen => listen)
end
end

super(:listen => listen)
end
end

Expand Down

0 comments on commit 3b3d7fe

Please sign in to comment.