class Mon::Monad::Future
Public Class Methods
[](obj)
click to toggle source
Wrap an object in a Future
. It will start off as complete, but functions that you bind to it will be asynchronous. value = Future["some_username"] futureBirthday = value.bind { |username| db.fetchUserInfo(username).getBirthday } # Returns a FuturePromise, wrapping an inflight thread puts "We have a birthday for some_username: #{ futureBirthday.unwrap }"
# File lib/monads/future.rb, line 40 def self::[](obj) FutureComplete[obj] end
eventually(*args, &fun)
click to toggle source
Create a Future
, executing some function, with optional arguments. Either: value = Future::eventually { do_something_slow }
Or: value = Future::eventually(myValue) { |val| do_something_slow(val) }
# File lib/monads/future.rb, line 31 def self::eventually *args, &fun FuturePromise::perform(fun, args) end
valid?(v)
click to toggle source
For use with contracts, DEPRECATED
# File lib/monads/future.rb, line 62 def self::valid?(v) v.is_a?(Mon::Future) end
Public Instance Methods
==(o)
click to toggle source
# File lib/monads/future.rb, line 57 def == o eql? o end
eql?(o)
click to toggle source
# File lib/monads/future.rb, line 44 def eql? o # Time to collapse if o.is_a? Future self.unwrap == o.unwrap else self.unwrap == o end end
equals?(o)
click to toggle source
# File lib/monads/future.rb, line 53 def equals? o eql? o end