Class: Fibril::FFuture
Instance Attribute Summary
Attributes inherited from Future
Instance Method Summary collapse
-
#initialize(&blk) ⇒ FFuture
constructor
A Forked future.
Methods inherited from Future
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 |