Class: Session::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/jiji/util/block_to_session.rb

Overview

リクエスト

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Request

Returns a new instance of Request.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jiji/util/block_to_session.rb', line 38

def initialize( block )
  @mutex = Mutex.new
  @cv = ConditionVariable.new
  @finished = false
  @value = nil
  @error = nil
  @proc = proc {|*args|
    begin
      @value = block.call(*args)
    rescue Exception
      @error = $! 
    ensure
      @mutex.synchronize{
        @finished = true
        @cv.signal
      }
    end
  }
end

Instance Method Details

#call(*args) ⇒ Object

リクエストを実行する。



66
67
68
# File 'lib/jiji/util/block_to_session.rb', line 66

def call(*args)
  @proc.call(*args)
end

#waitObject

リクエストの完了を待ち、結果を返す。

Raises:

  • (@error)


58
59
60
61
62
63
64
# File 'lib/jiji/util/block_to_session.rb', line 58

def wait
  @mutex.synchronize{
    @cv.wait( @mutex ) until @finished
  }
  raise @error if @error
  @value
end