Class: Bundler::Worker
- Inherits:
- 
      Object
      
        - Object
- Bundler::Worker
 
- Defined in:
- lib/bundler/worker.rb
Defined Under Namespace
Classes: WrappedException
Constant Summary collapse
- POISON =
- Object.new 
Instance Attribute Summary collapse
- 
  
    
      #name  ⇒ String 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    The name of the worker. 
Instance Method Summary collapse
- 
  
    
      #deq  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Retrieves results of job function being executed in worker pool. 
- 
  
    
      #enq(obj)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Enqueue a request to be executed in the worker pool. 
- 
  
    
      #initialize(size, name, func)  ⇒ Worker 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Creates a worker pool of specified size. 
- #stop ⇒ Object
Constructor Details
#initialize(size, name, func) ⇒ Worker
Creates a worker pool of specified size
| 22 23 24 25 26 27 28 29 30 | # File 'lib/bundler/worker.rb', line 22 def initialize(size, name, func) @name = name @request_queue = Thread::Queue.new @response_queue = Thread::Queue.new @func = func @size = size @threads = nil @previous_interrupt_handler = nil end | 
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the worker.
| 15 16 17 | # File 'lib/bundler/worker.rb', line 15 def name @name end | 
Instance Method Details
#deq ⇒ Object
Retrieves results of job function being executed in worker pool
| 41 42 43 44 45 | # File 'lib/bundler/worker.rb', line 41 def deq result = @response_queue.deq raise result.exception if result.is_a?(WrappedException) result end | 
#enq(obj) ⇒ Object
Enqueue a request to be executed in the worker pool
| 35 36 37 38 | # File 'lib/bundler/worker.rb', line 35 def enq(obj) create_threads unless @threads @request_queue.enq obj end | 
#stop ⇒ Object
| 47 48 49 | # File 'lib/bundler/worker.rb', line 47 def stop stop_threads end |