Class: Asap::FetchContext
- Inherits:
-
Object
- Object
- Asap::FetchContext
- Defined in:
- lib/asap/fetch_context.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #get(url, &blk) ⇒ Object
-
#initialize ⇒ FetchContext
constructor
A new instance of FetchContext.
- #join ⇒ Object
Constructor Details
#initialize ⇒ FetchContext
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
#result ⇒ Object (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 |
#join ⇒ Object
27 28 29 |
# File 'lib/asap/fetch_context.rb', line 27 def join @semaphore.acquire(@result.size) end |