Class: IFuture
- Inherits:
-
Object
- Object
- IFuture
- Defined in:
- lib/ifuture.rb,
lib/ifuture/version.rb
Constant Summary collapse
- VERSION =
'0.3.3'
Class Method Summary collapse
- .redis(serializer = Marshal, options = {}, &block) ⇒ Object
- .unix(serializer = Marshal, options = {}, &block) ⇒ Object
Instance Method Summary collapse
-
#initialize(channel, block) ⇒ IFuture
constructor
A new instance of IFuture.
- #ready? ⇒ Boolean
- #value ⇒ Object
Constructor Details
#initialize(channel, block) ⇒ IFuture
Returns a new instance of IFuture.
17 18 19 20 |
# File 'lib/ifuture.rb', line 17 def initialize(channel, block) @channel = channel @pid = fork { @channel.put(block.call) } end |
Class Method Details
.redis(serializer = Marshal, options = {}, &block) ⇒ Object
11 12 13 14 15 |
# File 'lib/ifuture.rb', line 11 def self.redis(serializer = Marshal, = {}, &block) allocate.tap do |obj| obj.send :initialize, IChannel.redis(serializer, ), block end end |
.unix(serializer = Marshal, options = {}, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/ifuture.rb', line 5 def self.unix(serializer = Marshal, = {}, &block) allocate.tap do |obj| obj.send :initialize, IChannel.unix(serializer, ), block end end |
Instance Method Details
#ready? ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/ifuture.rb', line 23 def ready? if defined? @value true else @channel.readable? end end |
#value ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ifuture.rb', line 31 def value if defined? @value @value else Process.wait @pid @value = @channel.get end end |