Class: IFuture

Inherits:
Object
  • Object
show all
Defined in:
lib/ifuture.rb,
lib/ifuture/version.rb

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ IFuture

Returns a new instance of IFuture.



5
6
7
8
9
10
11
# File 'lib/ifuture.rb', line 5

def initialize &block
  @channel = IChannel.new Marshal
  
  @pid = fork do
    @channel.put block.call
  end
end

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
# File 'lib/ifuture.rb', line 13

def ready?
  begin
    !Process.getpgid(@pid)
  rescue Errno::ESRCH
    true
  end
end

#valueObject



21
22
23
24
# File 'lib/ifuture.rb', line 21

def value
  Process.wait @pid
  @channel.get
end