Class: Klenod::Build::AssetGenerationQueue
- Inherits:
-
Object
- Object
- Klenod::Build::AssetGenerationQueue
- Defined in:
- lib/klenod/build/asset_generation_queue.rb
Constant Summary collapse
- DEFAULT_CONCURRENCY =
[Etc.nprocessors / 2, 2].max
- DEFAULT_DOWNLOAD_CONCURRENCY =
4
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#download_concurrency ⇒ Object
readonly
Returns the value of attribute download_concurrency.
Instance Method Summary collapse
-
#initialize(concurrency: DEFAULT_CONCURRENCY, download_concurrency: DEFAULT_DOWNLOAD_CONCURRENCY) ⇒ AssetGenerationQueue
constructor
A new instance of AssetGenerationQueue.
- #run(kind: :cpu, &block) ⇒ Object
Constructor Details
#initialize(concurrency: DEFAULT_CONCURRENCY, download_concurrency: DEFAULT_DOWNLOAD_CONCURRENCY) ⇒ AssetGenerationQueue
Returns a new instance of AssetGenerationQueue.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/klenod/build/asset_generation_queue.rb', line 15 def initialize(concurrency: DEFAULT_CONCURRENCY, download_concurrency: DEFAULT_DOWNLOAD_CONCURRENCY) @concurrency = Integer(concurrency) @download_concurrency = Integer(download_concurrency) raise ArgumentError, "concurrency must be positive" unless @concurrency.positive? raise ArgumentError, "download_concurrency must be positive" unless @download_concurrency.positive? @semaphores = { cpu: Async::Semaphore.new(@concurrency), io: Async::Semaphore.new(@download_concurrency) } end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
13 14 15 |
# File 'lib/klenod/build/asset_generation_queue.rb', line 13 def concurrency @concurrency end |
#download_concurrency ⇒ Object (readonly)
Returns the value of attribute download_concurrency.
13 14 15 |
# File 'lib/klenod/build/asset_generation_queue.rb', line 13 def download_concurrency @download_concurrency end |
Instance Method Details
#run(kind: :cpu, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/klenod/build/asset_generation_queue.rb', line 27 def run(kind: :cpu, &block) semaphore = semaphore_for(kind) task = current_async_task return semaphore.acquire { block.call } unless task semaphore.async(parent: task) { block.call } end |