Class: HTTPClient::Connection

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

Overview

HTTPClient::Connection – magage a connection(one request and response to it).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header_queue = [], body_queue = []) ⇒ Connection

Returns a new instance of Connection.



744
745
746
747
748
749
# File 'lib/httpclient.rb', line 744

def initialize(header_queue = [], body_queue = [])
  @headers = header_queue
  @body = body_queue
  @async_thread = nil
  @queue = Queue.new
end

Instance Attribute Details

#async_threadObject

:nodoc:



742
743
744
# File 'lib/httpclient.rb', line 742

def async_thread
  @async_thread
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'lib/httpclient.rb', line 751

def finished?
  if !@async_thread
    # Not in async mode.
    true
  elsif @async_thread.alive?
    # Working...
    false
  else
    # Async thread have been finished.
    @async_thread.join
    true
  end
end

#joinObject



773
774
775
776
777
778
779
# File 'lib/httpclient.rb', line 773

def join
  unless @async_thread
    false
  else
    @async_thread.join
  end
end

#popObject



765
766
767
# File 'lib/httpclient.rb', line 765

def pop
  @queue.pop
end

#push(result) ⇒ Object



769
770
771
# File 'lib/httpclient.rb', line 769

def push(result)
  @queue.push(result)
end