Class: InternetHakai::TaskQueue

Inherits:
BaseHandler show all
Defined in:
lib/internethakai/hakairev/task.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) ⇒ TaskQueue

Returns a new instance of TaskQueue.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/internethakai/hakairev/task.rb', line 5

def initialize id
    super(id)
    @queue = []
    #@queue = Queue::new
    #@watcher = Rev::AsyncWatcher::new
    #this = self
    #task = lambda{
    #    this.run
    #}
    #@watcher.on_signal(&task)
end

Instance Method Details

#add(v) ⇒ Object



23
24
25
26
27
28
# File 'lib/internethakai/hakairev/task.rb', line 23

def add v
    #puts "add"
    @queue.push(v)
    #@queue.enq(v)
    #@watcher.signal
end

#clearObject

@queue.enq(v)



29
30
31
32
33
# File 'lib/internethakai/hakairev/task.rb', line 29

def clear
    while !@queue.empty?
        run
    end
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/internethakai/hakairev/task.rb', line 20

def empty?
    @queue.empty?
end

#getObject

this = self task = lambda

this.run

@watcher.on_signal(&task)



16
17
18
19
# File 'lib/internethakai/hakairev/task.rb', line 16

def get
    @queue.shift
    #@queue.deq
end

#runObject



34
35
36
37
# File 'lib/internethakai/hakairev/task.rb', line 34

def run
    task, args = @queue.shift
    task.call(*args) if task
end