Skip to content

Commit 14d4598

Browse files
committed
Minor refactoring and doc updates.
1 parent a9da183 commit 14d4598

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

lib/concurrent/delay.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Delay < Synchronization::Object
6060
def initialize(opts = {}, &block)
6161
raise ArgumentError.new('no block given') unless block_given?
6262

63-
super(&nil)
63+
super()
6464
init_obligation(self)
6565
set_deref_options(opts)
6666
@task_executor = get_executor_from(opts)

lib/concurrent/dereferenceable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def value
4747

4848
# Set the internal value of this object
4949
#
50-
# @param [Object] val the new value
50+
# @param [Object] value the new value
5151
def value=(value)
5252
mutex.synchronize{ @value = value }
5353
end

lib/concurrent/ivar.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ def add_observer(observer = nil, func = :update, &block)
100100

101101
# Set the `IVar` to a value and wake or notify all threads waiting on it.
102102
#
103-
# @param [Object] value the value to store in the `IVar`
104-
# @raise [Concurrent::MultipleAssignmentError] if the `IVar` has already
105-
# been set or otherwise completed
103+
# @!macro [attach] ivar_set_parameters_and_exceptions
104+
# @param [Object] value the value to store in the `IVar`
105+
# @yield A block operation to use for setting the value
106+
# @raise [ArgumentError] if both a value and a block are given
107+
# @raise [Concurrent::MultipleAssignmentError] if the `IVar` has already
108+
# been set or otherwise completed
109+
#
106110
# @return [IVar] self
107111
def set(value = NO_VALUE)
108112
check_for_block_or_value!(block_given?, value)
@@ -123,9 +127,15 @@ def set(value = NO_VALUE)
123127
# been set or otherwise completed
124128
# @return [IVar] self
125129
def fail(reason = StandardError.new)
126-
set { raise reason }
130+
complete(false, nil, reason)
127131
end
128132

133+
# Attempt to set the `IVar` with the given value or block. Return a
134+
# boolean indicating the success or failure of the set operation.
135+
#
136+
# @!macro ivar_set_parameters_and_exceptions
137+
#
138+
# @return [Boolean] true if the value was set else false
129139
def set?(value = NO_VALUE, &block)
130140
set(value, &block)
131141
true

lib/concurrent/promise.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def set(value = IVar::NO_VALUE, &block)
253253
execute
254254
end
255255

256+
def fail(reason = StandardError.new)
257+
set { raise reason }
258+
end
259+
256260
# Create a new `Promise` object with the given block, execute it, and return the
257261
# `:pending` object.
258262
#

lib/concurrent/synchronization/abstract_object.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ module Synchronization
77
# Provides a single layer which can improve its implementation over time without changes needed to
88
# the classes using it. Use {Synchronization::Object} not this abstract class.
99
#
10-
# @note this object does not support usage together with {Thread#wakeup} and {Thread#raise}.
10+
# @note this object does not support usage together with
11+
# [Thread#wakeup](http://ruby-doc.org/core-2.2.0/Thread.html#method-i-wakeup)
12+
# and [Thread#raise](http://ruby-doc.org/core-2.2.0/Thread.html#method-i-raise).
1113
# `Thread#sleep` and `Thread#wakeup` will work as expected but mixing `Synchronization::Object#wait` and
1214
# `Thread#wakeup` will not work on all platforms.
1315
#

0 commit comments

Comments
 (0)