Class: HTTPAccess2::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/http-access2.rb

Overview

HTTPAccess2::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.



792
793
794
795
796
797
# File 'lib/http-access2.rb', line 792

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:



790
791
792
# File 'lib/http-access2.rb', line 790

def async_thread
  @async_thread
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/http-access2.rb', line 799

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



821
822
823
824
825
826
827
# File 'lib/http-access2.rb', line 821

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

#popObject



813
814
815
# File 'lib/http-access2.rb', line 813

def pop
  @queue.pop
end

#push(result) ⇒ Object



817
818
819
# File 'lib/http-access2.rb', line 817

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