Class: Asap::FetchContext

Inherits:
Object
  • Object
show all
Defined in:
lib/asap/fetch_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFetchContext

Returns a new instance of FetchContext.



5
6
7
8
# File 'lib/asap/fetch_context.rb', line 5

def initialize
  @result = []
  @semaphore = java.util.concurrent.Semaphore.new(0)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



31
32
33
# File 'lib/asap/fetch_context.rb', line 31

def result
  @result
end

Instance Method Details

#get(url, &blk) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/asap/fetch_context.rb', line 10

def get(url, &blk)
  target_index = @result.size
  @result << nil
  Asap::Netty.get(url) do |result|
    if blk
      Thread.new do
        nested = Asap(result, &blk)
        @result[target_index] = [result, nested]
        @semaphore.release
      end
    else
      @result[target_index] = result
      @semaphore.release
    end
  end
end

#joinObject



27
28
29
# File 'lib/asap/fetch_context.rb', line 27

def join
  @semaphore.acquire(@result.size)
end