Skip to content

Commit f7d4ed0

Browse files
committed
update actor examples
1 parent 2acd02a commit f7d4ed0

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

doc/actor/define.out.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ def on_event(event)
3333
an_actor << :boo << Message.new(:add, 1)
3434
an_actor.ask!(Message.new(:value, nil)) # => 1
3535
an_actor << :terminate!
36-
# => #<Concurrent::Actor::Reference:0x7fb6fc9165d0 /an_actor (AnActor)>
36+
# => #<Concurrent::Actor::Reference:0x7ff3ab16edc8 /an_actor (AnActor)>
3737

doc/actor/io.in.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ def on_message(message)
1111
end
1212

1313
def default_executor
14-
Concurrent.configuration.global_operation_pool
14+
Concurrent.global_io_executor
1515
end
1616
end #
1717

1818
actor_doing_io = ActorDoingIO.spawn :actor_doing_io
19-
actor_doing_io.executor == Concurrent.configuration.global_operation_pool
19+
actor_doing_io.executor == Concurrent.global_io_executor
2020

2121
# It can be also built into a pool so there is not too many IO operations
2222

23-
class IOWorker < Concurrent::Actor::Utils::AbstractWorker
24-
def work(io_job)
23+
class IOWorker < Concurrent::Actor::Context
24+
def on_message(io_job)
2525
# do IO work
2626
sleep 0.1
2727
puts "#{path} second:#{(Time.now.to_f*100).floor} message:#{io_job}"
2828
end
2929

3030
def default_executor
31-
Concurrent.configuration.global_operation_pool
31+
Concurrent.global_io_executor
3232
end
3333
end #
3434

35-
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |balancer, index|
36-
IOWorker.spawn(name: "worker-#{index}", args: [balancer])
35+
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |index|
36+
IOWorker.spawn(name: "worker-#{index}")
3737
end
3838

3939
pool << 1 << 2 << 3 << 4 << 5 << 6

doc/actor/io.out.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ def on_message(message)
1111
end
1212

1313
def default_executor
14-
Concurrent.configuration.global_operation_pool
14+
Concurrent.global_io_executor
1515
end
1616
end
1717

1818
actor_doing_io = ActorDoingIO.spawn :actor_doing_io
19-
# => #<Concurrent::Actor::Reference:0x7fb6fc906068 /actor_doing_io (ActorDoingIO)>
20-
actor_doing_io.executor == Concurrent.configuration.global_operation_pool
19+
# => #<Concurrent::Actor::Reference:0x7ff3ab176b40 /actor_doing_io (ActorDoingIO)>
20+
actor_doing_io.executor == Concurrent.global_io_executor
2121
# => true
2222

2323
# It can be also built into a pool so there is not too many IO operations
2424

25-
class IOWorker < Concurrent::Actor::Utils::AbstractWorker
26-
def work(io_job)
25+
class IOWorker < Concurrent::Actor::Context
26+
def on_message(io_job)
2727
# do IO work
2828
sleep 0.1
2929
puts "#{path} second:#{(Time.now.to_f*100).floor} message:#{io_job}"
3030
end
3131

3232
def default_executor
33-
Concurrent.configuration.global_operation_pool
33+
Concurrent.global_io_executor
3434
end
3535
end
3636

37-
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |balancer, index|
38-
IOWorker.spawn(name: "worker-#{index}", args: [balancer])
37+
pool = Concurrent::Actor::Utils::Pool.spawn('pool', 2) do |index|
38+
IOWorker.spawn(name: "worker-#{index}")
3939
end
40-
# => #<Concurrent::Actor::Reference:0x7fb6fc964190 /pool (Concurrent::Actor::Utils::Pool)>
40+
# => #<Concurrent::Actor::Reference:0x7ff3abaac5c0 /pool (Concurrent::Actor::Utils::Pool)>
4141

4242
pool << 1 << 2 << 3 << 4 << 5 << 6
43-
# => #<Concurrent::Actor::Reference:0x7fb6fc964190 /pool (Concurrent::Actor::Utils::Pool)>
43+
# => #<Concurrent::Actor::Reference:0x7ff3abaac5c0 /pool (Concurrent::Actor::Utils::Pool)>
4444

4545
# prints two lines each second
4646
# /pool/worker-0 second:1414677666 message:1

doc/actor/messaging.out.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'algebrick' # => false
1+
require 'algebrick' # => true
22

33
# Actor message protocol definition with Algebrick
44
Protocol = Algebrick.type do
@@ -24,13 +24,13 @@ def on_message(message)
2424
end
2525

2626
calculator = Calculator.spawn('calculator')
27-
# => #<Concurrent::Actor::Reference:0x7fb6fc915ec8 /calculator (Calculator)>
27+
# => #<Concurrent::Actor::Reference:0x7ff3ab0c4f80 /calculator (Calculator)>
2828
addition = calculator.ask Add[1, 2]
29-
# => <#Concurrent::Edge::Future:0x7fb6fc937190 pending blocks:[]>
29+
# => <#Concurrent::Edge::Future:0x7ff3ab08e188 pending blocks:[]>
3030
substraction = calculator.ask Subtract[1, 0.5]
31-
# => <#Concurrent::Edge::Future:0x7fb6fc935598 pending blocks:[]>
31+
# => <#Concurrent::Edge::Future:0x7ff3ab9de940 pending blocks:[]>
3232
results = (addition & substraction)
33-
# => <#Concurrent::Edge::ArrayFuture:0x7fb6fc967ea8 pending blocks:[]>
33+
# => <#Concurrent::Edge::Future:0x7ff3aa0b1b48 pending blocks:[]>
3434
results.value! # => [3, 0.5]
3535

3636
calculator.ask! :terminate! # => true

doc/actor/quick.out.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def on_message(message)
1717
# `link: true` makes the actor linked to root actor and supervised
1818
# which is default behavior
1919
adder = Adder.spawn(name: :adder, link: true, args: [1])
20-
# => #<Concurrent::Actor::Reference:0x7fb6fc88ff58 /adder (Adder)>
20+
# => #<Concurrent::Actor::Reference:0x7ff3ababf828 /adder (Adder)>
2121
adder.parent
22-
# => #<Concurrent::Actor::Reference:0x7fb6fe0f5db8 / (Concurrent::Actor::Root)>
22+
# => #<Concurrent::Actor::Reference:0x7ff3abad7ba8 / (Concurrent::Actor::Root)>
2323

2424
# tell and forget
2525
adder.tell(:add).tell(:add)
26-
# => #<Concurrent::Actor::Reference:0x7fb6fc88ff58 /adder (Adder)>
26+
# => #<Concurrent::Actor::Reference:0x7ff3ababf828 /adder (Adder)>
2727
# ask to get result
2828
adder.ask!(:add) # => 4
2929
# fail the actor

doc/actor/supervision_tree.in.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def on_message(msg)
1111
when :listener
1212
@listener
1313
when :reset, :terminated, :resumed, :paused
14-
log Logger::DEBUG, " got #{msg} from #{envelope.sender}"
14+
log(DEBUG) { " got #{msg} from #{envelope.sender}"}
1515
else
1616
pass
1717
end

doc/actor/supervision_tree.out.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def on_message(msg)
1111
when :listener
1212
@listener
1313
when :reset, :terminated, :resumed, :paused
14-
log Logger::DEBUG, " got #{msg} from #{envelope.sender}"
14+
log(DEBUG) { " got #{msg} from #{envelope.sender}"}
1515
else
1616
pass
1717
end
@@ -48,22 +48,22 @@ def on_message(msg)
4848
end
4949

5050
master = Master.spawn(name: 'master', supervise: true)
51-
# => #<Concurrent::Actor::Reference:0x7fb6fca9caa8 /master (Master)>
51+
# => #<Concurrent::Actor::Reference:0x7ff3aa0d1380 /master (Master)>
5252
listener = master.ask!(:listener)
53-
# => #<Concurrent::Actor::Reference:0x7fb6fcabd9b0 /master/listener1 (Listener)>
54-
listener.ask!(:number) # => 53
53+
# => #<Concurrent::Actor::Reference:0x7ff3aa8776e8 /master/listener1 (Listener)>
54+
listener.ask!(:number) # => 73
5555

5656
master << :crash
57-
# => #<Concurrent::Actor::Reference:0x7fb6fca9caa8 /master (Master)>
57+
# => #<Concurrent::Actor::Reference:0x7ff3aa0d1380 /master (Master)>
5858

59-
sleep 0.1 # => 0
59+
sleep 0.1 # => 1
6060

6161
# ask for listener again, old one is terminated
6262
listener.ask!(:terminated?) # => true
6363
listener = master.ask!(:listener)
64-
# => #<Concurrent::Actor::Reference:0x7fb6fcb04ef0 /master/listener1 (Listener)>
65-
listener.ask!(:number) # => 71
64+
# => #<Concurrent::Actor::Reference:0x7ff3ab147110 /master/listener1 (Listener)>
65+
listener.ask!(:number) # => 48
6666

67-
master.ask!(:terminate!) # => true
67+
master.ask!(:terminate!) # => [true, true]
6868

6969
sleep 0.1 # => 0

0 commit comments

Comments
 (0)