Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved the YARD annotations.

* YARD doesn't define an Any type, use Object instead.
* YARD does define a Boolean pseudo-type which is (much) preferred to listing both true and false.
* YARD @example blocks don't need Markdown indentation (2 spaces is sufficient, and convention).
  • Loading branch information...
commit fa76bdd11af5b3c431ed4e8f8201deffbec65d13 1 parent ec7eb9e
@bendiken bendiken authored committed
Showing with 26 additions and 22 deletions.
  1. +10 −9 lib/future.rb
  2. +16 −13 lib/promise.rb
View
19 lib/future.rb
@@ -1,11 +1,12 @@
require 'promise'
##
-# A delayed-execution result, optimistcally evaluated in a new Thread.
+# A delayed-execution result, optimistically evaluated in a new thread.
+#
# @example
-# x = future { sleep 5; 1 + 2 }
-# # do stuff...
-# y = x * 2 # => 6. blocks unless 5 seconds has passed.
+# x = future { sleep 5; 1 + 2 }
+# # do stuff...
+# y = x * 2 # => 6. blocks unless 5 seconds has passed.
#
class Future < defined?(BasicObject) ? BasicObject : Object
instance_methods.each { |m| undef_method m unless m =~ /__/ } unless defined?(BasicObject)
@@ -23,7 +24,7 @@ def initialize(&block)
##
# The value of the future's evaluation. Blocks until result available.
#
- # @return [Any]
+ # @return [Object]
def __force__
@thread.join if @thread
@promise
@@ -31,10 +32,10 @@ def __force__
alias_method :force, :__force__
##
- # Does this promise support the given method?
+ # Does this future support the given method?
#
# @param [Symbol]
- # @return [true, false]
+ # @return [Boolean]
def respond_to?(method)
:force.equal?(method) || :__force__.equal?(method) || __force__.respond_to?(method)
end
@@ -53,11 +54,11 @@ module Kernel
# @example Evaluate an operation in another thread
# x = future { 3 + 3 }
#
- # @return [Future]
# @yield []
# A block to be optimistically evaluated in another thread.
- # @yieldreturn [Any]
+ # @yieldreturn [Object]
# The return value of the block will be the evaluated value of the future.
+ # @return [Future]
def future(&block)
Future.new(&block)
end
View
29 lib/promise.rb
@@ -1,16 +1,19 @@
##
# A delayed-execution promise. Promises are only executed once.
+#
# @example
-# x = promise { factorial 20 }
-# y = promise { fibonacci 10**6 }
-# a = x + 1 # => factorial 20 + 1 after factorial calculates
-# result = promise { a += y }
-# abort "" # whew, we never needed to calculate y
+# x = promise { factorial 20 }
+# y = promise { fibonacci 10**6 }
+# a = x + 1 # => factorial 20 + 1 after factorial calculates
+# result = promise { a += y }
+# abort "" # whew, we never needed to calculate y
+#
# @example
-# y = 5
-# x = promise { y = y + 5 }
-# x + 5 # => 15
-# x + 5 # => 15
+# y = 5
+# x = promise { y = y + 5 }
+# x + 5 # => 15
+# x + 5 # => 15
+#
class Promise < defined?(BasicObject) ? BasicObject : ::Object
NOT_SET = ::Object.new.freeze
@@ -37,7 +40,7 @@ def initialize(&block)
##
# Force the evaluation of this promise immediately
#
- # @return [Any]
+ # @return [Object]
def __force__
@mutex.synchronize do
if @result.equal?(NOT_SET) && @error.equal?(NOT_SET)
@@ -57,7 +60,7 @@ def __force__
# Does this promise support the given method?
#
# @param [Symbol]
- # @return [true, false]
+ # @return [Boolean]
def respond_to?(method)
:force.equal?(method) || :__force__.equal?(method) || __force__.respond_to?(method)
end
@@ -76,11 +79,11 @@ module Kernel
# @example Lazily evaluate an arithmetic operation
# x = promise { 3 + 3 }
#
- # @return [Promise]
# @yield []
# A block to be lazily evaluated.
- # @yieldreturn [Any]
+ # @yieldreturn [Object]
# The return value of the block will be the lazily evaluated value of the promise.
+ # @return [Promise]
def promise(&block)
Promise.new(&block)
end
Please sign in to comment.
Something went wrong with that request. Please try again.