@@ -19,36 +19,36 @@ module Concurrent
19
19
#
20
20
# An independent, concurrent, single-purpose, computational entity that communicates exclusively via message passing.
21
21
#
22
- # The ` Concurrent::Actor` class in this library is based solely on the
22
+ # The + Concurrent::Actor+ class in this library is based solely on the
23
23
# {http://www.scala-lang.org/api/current/index.html#scala.actors.Actor Actor} trait
24
24
# defined in the Scala standard library. It does not implement all the features of
25
- # Scala's ` Actor` but its behavior for what *has* been implemented is nearly identical.
25
+ # Scala's + Actor+ but its behavior for what *has* been implemented is nearly identical.
26
26
# The excluded features mostly deal with Scala's message semantics, strong typing,
27
27
# and other characteristics of Scala that don't really apply to Ruby.
28
28
#
29
- # Unlike most of the abstractions in this library, ` Actor` takes an *object-oriented*
29
+ # Unlike many of the abstractions in this library, + Actor+ takes an *object-oriented*
30
30
# approach to asynchronous concurrency, rather than a *functional programming*
31
31
# approach.
32
32
#
33
- # Because ` Actor` mixes in the ` Concurrent::Runnable` module subclasses have access to
34
- # the ` #on_error` method and can override it to implement custom error handling. The
35
- # ` Actor` base class does not use ` #on_error` so as to avoid conflit with subclasses
36
- # which override it. Generally speaking, ` #on_error` should not be used. The ` Actor`
33
+ # Because + Actor+ mixes in the + Concurrent::Runnable+ module subclasses have access to
34
+ # the + #on_error+ method and can override it to implement custom error handling. The
35
+ # + Actor+ base class does not use + #on_error+ so as to avoid conflit with subclasses
36
+ # which override it. Generally speaking, + #on_error+ should not be used. The + Actor+
37
37
# base class provides concictent, reliable, and robust error handling already, and
38
38
# error handling specifics are tied to the message posting method. Incorrect behavior
39
- # in an ` #on_error` override can lead to inconsistent ` Actor` behavior that may lead
39
+ # in an + #on_error+ override can lead to inconsistent + Actor+ behavior that may lead
40
40
# to confusion and difficult debugging.
41
41
#
42
- # The ` Actor` superclass mixes in the Ruby standard library
42
+ # The + Actor+ superclass mixes in the Ruby standard library
43
43
# {http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html Observable}
44
44
# module to provide consistent callbacks upon message processing completion. The normal
45
- # ` Observable` methods, including ` #add_observer` behave normally. Once an observer
46
- # is added to an ` Actor` it will be notified of all messages processed *after*
45
+ # + Observable+ methods, including + #add_observer+ behave normally. Once an observer
46
+ # is added to an + Actor+ it will be notified of all messages processed *after*
47
47
# addition. Notification will *not* occur for any messages that have already been
48
48
# processed.
49
49
#
50
50
# Observers will be notified regardless of whether the message processing is successful
51
- # or not. The ` #update` method of the observer will receive four arguments. The
51
+ # or not. The + #update+ method of the observer will receive four arguments. The
52
52
# appropriate method signature is:
53
53
#
54
54
# def update(time, message, result, reason)
@@ -57,8 +57,8 @@ module Concurrent
57
57
#
58
58
# * The time that message processing was completed
59
59
# * An array containing all elements of the original message, in order
60
- # * The result of the call to ` #act` (will be ` nil` if an exception was raised)
61
- # * Any exception raised by ` #act` (or ` nil` if message processing was successful)
60
+ # * The result of the call to + #act+ (will be + nil+ if an exception was raised)
61
+ # * Any exception raised by + #act+ (or + nil+ if message processing was successful)
62
62
#
63
63
# @example Actor Ping Pong
64
64
# class Ping < Concurrent::Actor
@@ -140,10 +140,10 @@ def initialize(queue)
140
140
141
141
# Create a pool of actors that share a common mailbox.
142
142
#
143
- # Every ` Actor` instance operates on its own thread. When one thread isn't enough capacity
144
- # to manage all the messages being sent to an ` Actor` a *pool* can be used instead. A pool
145
- # is a collection of ` Actor` instances, all of the same type, that shate a message queue.
146
- # Messages from other threads are all sent to a single queue against which all ` Actor` s
143
+ # Every + Actor+ instance operates on its own thread. When one thread isn't enough capacity
144
+ # to manage all the messages being sent to an + Actor+ a *pool* can be used instead. A pool
145
+ # is a collection of + Actor+ instances, all of the same type, that shate a message queue.
146
+ # Messages from other threads are all sent to a single queue against which all + Actor+ s
147
147
# load balance.
148
148
#
149
149
# @param [Integer] count the number of actors in the pool
@@ -152,7 +152,7 @@ def initialize(queue)
152
152
# @return [Array] two-element array with the shared mailbox as the first element
153
153
# and an array of actors as the second element
154
154
#
155
- # @raise ArgumentError if ` count` is zero or less
155
+ # @raise ArgumentError if + count+ is zero or less
156
156
#
157
157
# @example
158
158
# class EchoActor < Concurrent::Actor
@@ -191,35 +191,35 @@ def self.pool(count, *args, &block)
191
191
192
192
protected
193
193
194
- # Actors are defined by subclassing the ` Concurrent::Actor` class and overriding the
195
- # #act method. The #act method can have any signature/arity but ` def act(*args)`
194
+ # Actors are defined by subclassing the + Concurrent::Actor+ class and overriding the
195
+ # #act method. The #act method can have any signature/arity but + def act(*args)+
196
196
# is the most flexible and least error-prone signature. The #act method is called in
197
- # response to a message being post to the ` Actor` instance (see *Behavior* below).
197
+ # response to a message being post to the + Actor+ instance (see *Behavior* below).
198
198
#
199
199
# @param [Array] message one or more arguments representing the message sent to the
200
200
# actor via one of the Concurrent::Postable methods
201
201
#
202
202
# @return [Object] the result obtained when the message is successfully processed
203
203
#
204
- # @raise NotImplementedError unless overridden in the ` Actor` subclass
204
+ # @raise NotImplementedError unless overridden in the + Actor+ subclass
205
205
#
206
206
# @!visibility public
207
207
def act ( *message )
208
208
raise NotImplementedError . new ( "#{ self . class } does not implement #act" )
209
209
end
210
210
211
- # @private
211
+ # @!visibility private
212
212
def on_run # :nodoc:
213
213
queue . clear
214
214
end
215
215
216
- # @private
216
+ # @!visibility private
217
217
def on_stop # :nodoc:
218
218
queue . clear
219
219
queue . push ( :stop )
220
220
end
221
221
222
- # @private
222
+ # @!visibility private
223
223
def on_task # :nodoc:
224
224
package = queue . pop
225
225
return if package == :stop
@@ -235,8 +235,8 @@ def on_task # :nodoc:
235
235
if notifier . is_a? ( Event ) && ! notifier . set?
236
236
package . handler . push ( result || ex )
237
237
package . notifier . set
238
- elsif package . handler . is_a? ( Contract )
239
- package . handler . complete ( result , ex )
238
+ elsif package . handler . is_a? ( IVar )
239
+ package . handler . complete ( ! result . nil? , result , ex )
240
240
elsif package . handler . respond_to? ( :post ) && ex . nil?
241
241
package . handler . post ( result )
242
242
end
@@ -246,7 +246,7 @@ def on_task # :nodoc:
246
246
end
247
247
end
248
248
249
- # @private
249
+ # @!visibility private
250
250
def on_error ( time , msg , ex ) # :nodoc:
251
251
end
252
252
end
0 commit comments