Class: Proco::Future

Inherits:
Object
  • Object
show all
Includes:
MT::Base
Defined in:
lib/proco/future.rb

Instance Method Summary collapse

Methods included from MT::Base

#broadcast, #do_when, #signal, #synchronize, #try_when, #wait_until

Constructor Details

#initializeFuture

Returns a new instance of Future.



20
21
22
23
24
# File 'lib/proco/future.rb', line 20

def initialize
  super()
  @state = :wait
  @return = nil
end

Instance Method Details

#getObject



5
6
7
8
9
10
11
12
13
# File 'lib/proco/future.rb', line 5

def get
  do_when(proc { @state != :wait }) do
    if @state == :ok
      return @return
    else
      raise @return
    end
  end
end

#inspectObject



15
16
17
# File 'lib/proco/future.rb', line 15

def inspect
  "Future=#{@state}"
end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/proco/future.rb', line 27

def update
  begin
    @return = yield
    @state = :ok
  rescue Exception => e
    @return = e
    @state = :fail
  end

  broadcast
end