Class: Celluloid::Actor::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/celluloid/lib/celluloid/actor_pool.rb

Overview

Maintain a thread pool of actors FOR SPEED!!

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.max_idleObject

Returns the value of attribute max_idle.



12
13
14
# File 'lib/vendor/celluloid/lib/celluloid/actor_pool.rb', line 12

def max_idle
  @max_idle
end

Class Method Details

.createObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vendor/celluloid/lib/celluloid/actor_pool.rb', line 37

def create
  queue = Queue.new
  thread = Thread.new do
    begin
      while func = queue.pop
        func.call
      end
    rescue Exception => ex
      Logger.crash("#{self} internal failure", ex)
    end
  end
  thread[:queue] = queue
  thread
end

.get(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vendor/celluloid/lib/celluloid/actor_pool.rb', line 14

def get(&block)
  @lock.synchronize do
    if @pool.empty?
      thread = create
    else
      thread = @pool.shift
    end

    thread[:queue] << block
    thread
  end
end

.put(thread) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/vendor/celluloid/lib/celluloid/actor_pool.rb', line 27

def put(thread)
  @lock.synchronize do
    if @pool.size >= @max_idle
      thread[:queue] << nil
    else
      @pool << thread
    end
  end
end