Class: IFuture

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

Constant Summary collapse

VERSION =
'0.3.3'

Class Method Summary collapse

Instance Method Summary collapse

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, options = {}, &block)
  allocate.tap do |obj|
    obj.send :initialize, IChannel.redis(serializer, options), 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, options = {}, &block)
  allocate.tap do |obj|
    obj.send :initialize, IChannel.unix(serializer, options), block
  end
end

Instance Method Details

#ready?Boolean

Returns:

  • (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

#valueObject



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