lib/async/container.rb in async-container-0.9.0 vs lib/async/container.rb in async-container-0.10.0

- old
+ new

@@ -16,21 +16,23 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +require_relative 'container/forked' require_relative 'container/threaded' +require_relative 'container/hybrid' require 'etc' module Async - # Manages a reactor within one or more threads. + # Containers execute one or more "instances" which typically contain a reactor. A container spawns "instances" using threads and/or processes. Because these are resources that must be cleaned up some how (either by `join` or `waitpid`), their creation is deferred until the user invokes `Container#wait`. When executed this way, the container guarantees that all "instances" will be complete once `Container#wait` returns. Containers are constructs for achieving parallelism, and are not designed to be used directly for concurrency. Typically, you'd create one or more container, add some tasks to it, and then wait for it to complete. module Container - def self.new(**options, &block) - Threaded.new(**options, &block) + def self.run(concurrency_class: Threaded, **options, &block) + concurrency_class.run(**options, &block) end - def self.hardware_concurrency + def self.processor_count Etc.nprocessors rescue 2 end end