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.



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

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:



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

def async_thread
  @async_thread
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


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

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



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

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

#popObject



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

def pop
  @queue.pop
end

#push(result) ⇒ Object



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

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