lib/async/container.rb in async-container-0.10.2 vs lib/async/container.rb in async-container-0.11.0
- old
+ new
@@ -25,16 +25,24 @@
require 'etc'
module Async
# 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.run(concurrency_class: Threaded, **options, &block)
- concurrency_class.run(**options, &block)
+ def self.best_container_class
+ if Process.respond_to?(:fork) and Process.respond_to(:setpgid)
+ return Forked
+ else
+ return Threaded
+ end
end
def self.processor_count
Etc.nprocessors
rescue
2
+ end
+
+ def self.new
+ best_container_class.new(*arguments)
end
end
end