Class: WaybackArchiver::ThreadPool

Inherits:
Object
  • Object
show all
Defined in:
lib/wayback_archiver/thread_pool.rb

Overview

Thread pool

Class Method Summary collapse

Class Method Details

.build(concurrency) ⇒ Concurrent::FixedThreadPool/Concurrent::ImmediateExecutor

Build a thread pool

Examples:

Build a thread pool with 10 as the desired concurrency

pool = ThreadPool.build(10)
pool.post { some_work } # Returns a Concurrent::FixedThreadPool

Build a thread pool with 1 as the desired concurrency

pool = ThreadPool.build(1)
pool.post { some_work } # Returns a Concurrent::ImmediateExecutor

Parameters:

  • concurrency (Integer)

    the desired concurrency

Returns:

  • (Concurrent::FixedThreadPool/Concurrent::ImmediateExecutor)

    an instance of a concurrent thread pool

See Also:



16
17
18
19
20
21
22
23
24
# File 'lib/wayback_archiver/thread_pool.rb', line 16

def self.build(concurrency)
  if concurrency == 1
    Concurrent::ImmediateExecutor.new
  elsif concurrency > 1
    Concurrent::FixedThreadPool.new(concurrency)
  else
    raise ArgumentError, 'concurrency must be one or greater'
  end
end