Class: Canopus::DisplayMap::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/canopus/display_map/worker.rb

Defined Under Namespace

Classes: Job, Result

Constant Summary collapse

BATCH_LINES =
32
QUEUE_LIMIT =
8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Worker

Returns a new instance of Worker.



12
13
14
15
16
17
# File 'lib/canopus/display_map/worker.rb', line 12

def initialize
  @requests, @results = Queue.new, SizedQueue.new(QUEUE_LIMIT)
  @thread = Thread.new { run }
  @thread.name = "canopus-wrap"
  @thread.report_on_exception = false
end

Instance Attribute Details

#results ⇒ Object (readonly)

Returns the value of attribute results.



10
11
12
# File 'lib/canopus/display_map/worker.rb', line 10

def results
  @results
end

#thread ⇒ Object (readonly)

Returns the value of attribute thread.



10
11
12
# File 'lib/canopus/display_map/worker.rb', line 10

def thread
  @thread
end

Instance Method Details

#close ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/canopus/display_map/worker.rb', line 26

def close
  return if @closed
  @closed = true
  @generation = nil
  @requests.close
  @results.close
  # Cancellation checkpoints normally finish in milliseconds. No native
  # resource or shared mutable document state belongs to this worker.
  @thread.kill unless @thread.join(1)
  @thread.join(0.1)
  @results.clear
end

#submit(generation, tree, builder, prefix) ⇒ Object



19
20
21
22
23
24
# File 'lib/canopus/display_map/worker.rb', line 19

def submit(generation, tree, builder, prefix)
  @generation = generation
  @requests.clear
  @results.clear
  @requests << Job.new(generation, tree, builder, prefix)
end