Class: InternetHakai::RequestPool

Inherits:
BaseHandler show all
Defined in:
lib/internethakai/executor.rb

Constant Summary collapse

UNIQUE_BY_THREAD =
false

Instance Method Summary collapse

Methods inherited from BaseHandler

clear, clearall, get_class, get_config, get_handler, get_instance, get_instance_thread, get_thread_id, #on_create, set_config, set_thread_id, unique_by_thread?

Constructor Details

#initialize(id) ⇒ RequestPool

Returns a new instance of RequestPool.



5
6
7
8
9
# File 'lib/internethakai/executor.rb', line 5

def initialize id
    @queue = Queue::new
    @enable = true
    @closed = false
end

Instance Method Details

#add(action) ⇒ Object



14
15
16
17
# File 'lib/internethakai/executor.rb', line 14

def add action
    return unless @enable
    @queue.enq(action)
end

#clearObject



10
11
12
13
# File 'lib/internethakai/executor.rb', line 10

def clear
    @queue.clear
    @queue = Queue::new
end

#closeObject



30
31
32
33
34
35
36
# File 'lib/internethakai/executor.rb', line 30

def close
    @closed = true
    1.upto(@queue.num_waiting) do
        @queue.enq(-1)
    end
    @queue.clear
end

#empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/internethakai/executor.rb', line 18

def empty?
    @queue.empty?
end

#getObject



21
22
23
24
25
26
27
28
29
# File 'lib/internethakai/executor.rb', line 21

def get
    return if @closed
    r = @queue.deq
    if ! @enable and @queue.empty?
        #enable=false で キューが空になった時点でclose
        close
    end
    return r
end

#quitObject



37
38
39
40
41
# File 'lib/internethakai/executor.rb', line 37

def quit
    @enable = false
    #enable=false で キューが空になった時点でclose
    close if @queue.empty?
end