Skip to content

Commit

Permalink
Add support for getting hardware concurrency.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 27, 2018
1 parent 7e28b2e commit b1567fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/async/container.rb
Expand Up @@ -20,11 +20,19 @@

require_relative 'container/threaded'

require 'etc'

module Async
# Manages a reactor within one or more threads.
module Container
def self.new(**options, &block)
Threaded.new(**options, &block)
end

def self.hardware_concurrency
Etc.nprocessors
rescue
2
end
end
end
2 changes: 1 addition & 1 deletion lib/async/container/version.rb
Expand Up @@ -20,6 +20,6 @@

module Async
module Container
VERSION = "0.2.2"
VERSION = "0.3.0"
end
end
4 changes: 4 additions & 0 deletions spec/async/container_spec.rb
Expand Up @@ -32,4 +32,8 @@

expect(count).to be == 1
end

it "can get hardware concurrency" do
expect(Async::Container.hardware_concurrency).to be >= 1
end
end

0 comments on commit b1567fa

Please sign in to comment.