Skip to content

Commit 30a2a8e

Browse files
committed
Doc update
1 parent 0c903e4 commit 30a2a8e

21 files changed

+139
-59
lines changed

doc/actor/main.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Light-weighted.
44
- Inspired by Akka and Erlang.
5+
- Modular.
56

67
Actors are sharing a thread-pool by default which makes them very cheap to create and discard.
78
Thousands of actors can be created, allowing you to break the program into small maintainable pieces,
@@ -40,9 +41,9 @@ are very useful.
4041

4142
### Dead letter routing
4243

43-
see {Context#dead_letter_routing} description:
44+
see {AbstractContext#dead_letter_routing} description:
4445

45-
> {include:Actor::Context#dead_letter_routing}
46+
> {include:Actor::AbstractContext#dead_letter_routing}
4647
4748
## Architecture
4849

@@ -55,20 +56,19 @@ Blocking operations could starve the `default_task_pool`. However there are two
5556
- Create an actor using `global_operation_pool` instead of `global_task_pool`, e.g.
5657
`AnIOActor.spawn name: :blocking, executor: Concurrent.configuration.global_operation_pool`.
5758

58-
Each actor is composed from 3 objects:
59+
Each actor is composed from 4 parts:
5960

6061
### {Reference}
6162
{include:Actor::Reference}
6263

6364
### {Core}
6465
{include:Actor::Core}
6566

66-
### {Context}
67-
{include:Actor::Context}
67+
### {AbstractContext}
68+
{include:Actor::AbstractContext}
6869

69-
### Behaviours
70-
71-
_TODO_
70+
### {Behaviour}
71+
{include:Actor::Behaviour}
7272

7373
## Speed
7474

doc/actor/quick.in.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
class Counter
1+
class Counter < Concurrent::Actor::Context
22
# Include context of an actor which gives this class access to reference and other information
33
# about the actor, see PublicDelegations.
4-
include Concurrent::Actor::Context
54

65
# use initialize as you wish
76
def initialize(initial_value)
@@ -47,22 +46,18 @@ def on_message(message)
4746

4847

4948
# Lets define an actor creating children actors.
50-
class Node
51-
include Concurrent::Actor::Context
52-
49+
class Node < Concurrent::Actor::Context
5350
def on_message(message)
5451
case message
5552
when :new_child
56-
spawn self.class, :child
53+
Node.spawn :child
5754
when :how_many_children
5855
children.size
59-
when :terminate
60-
terminate!
6156
else
6257
raise 'unknown'
6358
end
6459
end
65-
end
60+
end #
6661

6762
# Actors are tracking parent-child relationships
6863
parent = Node.spawn :parent

doc/actor/quick.out.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
class Counter
1+
class Counter < Concurrent::Actor::Context
22
# Include context of an actor which gives this class access to reference and other information
33
# about the actor, see PublicDelegations.
4-
include Concurrent::Actor::Context
54

65
# use initialize as you wish
76
def initialize(initial_value)
@@ -42,27 +41,23 @@ def on_message(message)
4241

4342
# Failure on message processing terminates the actor.
4443
counter = Counter.spawn(:first, 0) # => #<Concurrent::Actor::Reference /first (Counter)>
45-
counter.ask('boom').wait.rejected? # => true
46-
counter.terminated? # => true
44+
counter.ask('boom').wait.rejected? # => false
45+
counter.terminated? # => false
4746

4847

4948
# Lets define an actor creating children actors.
50-
class Node
51-
include Concurrent::Actor::Context
52-
49+
class Node < Concurrent::Actor::Context
5350
def on_message(message)
5451
case message
5552
when :new_child
56-
spawn self.class, :child
53+
Node.spawn :child
5754
when :how_many_children
5855
children.size
59-
when :terminate
60-
terminate!
6156
else
6257
raise 'unknown'
6358
end
6459
end
65-
end # => :on_message
60+
end
6661

6762
# Actors are tracking parent-child relationships
6863
parent = Node.spawn :parent # => #<Concurrent::Actor::Reference /parent (Node)>

lib/concurrent/actor/behaviour.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
module Concurrent
22
module Actor
33

4-
# TODO document dependencies
4+
# Actors have modular architecture, which is achieved by combining a light core with chain of
5+
# behaviours. Each message or internal event propagates through the chain allowing the
6+
# behaviours react based on their responsibility. listing few as an example:
7+
#
8+
# - {Behaviour::Linking}:
9+
#
10+
# > {include:Actor::Behaviour::Linking}
11+
#
12+
# - {Behaviour::Awaits}:
13+
#
14+
# > {include:Actor::Behaviour::Awaits}
15+
#
16+
# See {Behaviour}'s namespace fo other behaviours.
17+
# If needed new behaviours can be added, or old one removed to get required behaviour.
518
module Behaviour
619
MESSAGE_PROCESSED = Object.new
720

lib/concurrent/actor/behaviour/abstract.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ def initialize(core, subsequent)
1212
@subsequent = Type! subsequent, Abstract, NilClass
1313
end
1414

15+
# override to add extra behaviour
16+
# @note super needs to be called not to break the chain
1517
def on_envelope(envelope)
1618
pass envelope
1719
end
1820

21+
# @param [Envelope] envelope to pass to {#subsequent} behaviour
1922
def pass(envelope)
2023
subsequent.on_envelope envelope
2124
end
2225

26+
# override to add extra behaviour
27+
# @note super needs to be called not to break the chain
2328
def on_event(event)
2429
subsequent.on_event event if subsequent
2530
end
2631

32+
# broadcasts event to all behaviours and context
33+
# @see #on_event
34+
# @see AbstractContext#on_event
2735
def broadcast(event)
2836
core.broadcast(event)
2937
end

lib/concurrent/actor/behaviour/awaits.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Handles `:await` messages. Which allows to wait on Actor to process all previously send
6+
# messages.
7+
# @example
8+
# actor << :a << :b
9+
# actor.ask(:await).wait # blocks until :a and :b are processed
410
class Awaits < Abstract
511
def on_envelope(envelope)
612
if envelope.message == :await

lib/concurrent/actor/behaviour/buffer.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Any message reaching this behaviour is buffered. Only one message is is scheduled
6+
# at any given time. Others are kept in buffer until another one can be scheduled.
7+
# This effective means that messages handled by behaviours before buffer have higher priority
8+
# and they can be processed before messages arriving into buffer. This allows to
9+
# process internal actor messages like (`:link`, `:supervise`) processed first.
410
class Buffer < Abstract
511
def initialize(core, subsequent)
612
super core, subsequent

lib/concurrent/actor/behaviour/errors_on_unknown_message.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# Simply fails when message arrives here.
45
class ErrorsOnUnknownMessage < Abstract
56
def on_envelope(envelope)
67
raise UnknownMessage, envelope

lib/concurrent/actor/behaviour/executes_context.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# Delegates messages nad events to {AbstractContext} instance
45
class ExecutesContext < Abstract
56
def on_envelope(envelope)
67
context.on_envelope envelope

lib/concurrent/actor/behaviour/linking.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Links the actor to other actors and sends events to them,
6+
# like: `:terminated`, `:paused`, errors, etc
47
class Linking < Abstract
58
def initialize(core, subsequent)
69
super core, subsequent

lib/concurrent/actor/behaviour/pausing.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Allows to pause actors on errors.
6+
# When paused all arriving messages are collected and processed after the actor
7+
# is resumed or reset. Resume will simply continue with next message.
8+
# Reset also reinitialized context. `:reset!` and `:resume!` messages are only accepted
9+
# form supervisor, see Supervised behaviour.
410
class Pausing < Abstract
511
def initialize(core, subsequent)
612
super core, subsequent

lib/concurrent/actor/behaviour/removes_child.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# Removes terminated children.
45
class RemovesChild < Abstract
56
def on_envelope(envelope)
67
if envelope.message == :remove_child

lib/concurrent/actor/behaviour/sets_results.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# Collects returning value and sets the IVar in the {Envelope} or error on failure.
45
class SetResults < Abstract
56
attr_reader :error_strategy
67

lib/concurrent/actor/behaviour/supervising.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Sets nad holds the supervisor of the actor if any. There is only one or none supervisor
6+
# for each actor. Each supervisor is automatically linked.
47
class Supervising < Abstract
58
attr_reader :supervisor
69

lib/concurrent/actor/behaviour/terminates_children.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
# Terminates all children when the actor terminates.
45
class TerminatesChildren < Abstract
56
def on_event(event)
67
children.each { |ch| ch << :terminate! } if event == :terminated

lib/concurrent/actor/behaviour/termination.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module Concurrent
22
module Actor
33
module Behaviour
4+
5+
# Handles actor termination.
6+
# @note Actor rejects envelopes when terminated.
47
class Termination < Abstract
58

69
# @!attribute [r] terminated

0 commit comments

Comments
 (0)