Class: Graticule::Geocoder::Multi::ParallelLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/graticule/geocoder/multi.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeParallelLookup

Returns a new instance of ParallelLookup.



77
78
79
80
# File 'lib/graticule/geocoder/multi.rb', line 77

def initialize
  @threads = []
  @monitor = Monitor.new
end

Instance Method Details

#perform(&block) ⇒ Object



82
83
84
85
86
# File 'lib/graticule/geocoder/multi.rb', line 82

def perform(&block)
  @threads << Thread.new do
    self.result = block.call
  end
end

#resultObject



97
98
99
100
# File 'lib/graticule/geocoder/multi.rb', line 97

def result
  @threads.each(&:join)
  @result
end

#result=(result) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/graticule/geocoder/multi.rb', line 88

def result=(result)
  if result
    @monitor.synchronize do
      @result = result
      @threads.each(&:kill)
    end
  end
end