Class: Mon::Monad::FutureComplete

Inherits:
Future show all
Defined in:
lib/monads/future.rb

Overview

FutureComplete represents a finalized value.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Future

#==, #eql?, #equals?, eventually, valid?

Methods included from ChainableMonad

#_, #coerce, #method_missing, #respond_to?

Constructor Details

#initialize(value) ⇒ FutureComplete

Returns a new instance of FutureComplete.



121
122
123
# File 'lib/monads/future.rb', line 121

def initialize(value)
  @value = value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mon::Monad::ChainableMonad

Class Method Details

.[](value) ⇒ Object

You should probably be using Future instead.



126
127
128
# File 'lib/monads/future.rb', line 126

def self::[](value)
  self::new(value)
end

Instance Method Details

#bind(&fun) ⇒ Object

Asyrchronously apply fun to the value wrapped by this FutureComplete. Returns a FuturePromise.



131
132
133
# File 'lib/monads/future.rb', line 131

def bind &fun
  FuturePromise::perform(fun, [@value])
end

#pending?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/monads/future.rb', line 135

def pending?
  false
end

#to_sObject



143
144
145
# File 'lib/monads/future.rb', line 143

def to_s
  "FutureComplete[#{ @value }]"
end

#unwrapObject



139
140
141
# File 'lib/monads/future.rb', line 139

def unwrap
  @value
end