Class: Fibril::FFuture

Inherits:
Future
  • Object
show all
Defined in:
lib/fibril/ffuture.rb

Instance Attribute Summary

Attributes inherited from Future

#future_thread

Instance Method Summary collapse

Methods inherited from Future

#alive?, #await, #close

Constructor Details

#initialize(&blk) ⇒ FFuture

A Forked future. Fulfils the same future api as Fibril::Future but runs the block inside a new fork instead of a new thread..



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fibril/ffuture.rb', line 9

def initialize(&blk)
  read, write = IO.pipe
  pid = fork do
    result = blk[]
    read.close
    Marshal.dump(result, write)
  end
  write.close
  result = nil
  self.future_thread = Thread.new do
    result = read.read
    Process.wait(pid)
    Marshal.load(result)
  end
end