@@ -713,7 +713,7 @@ message.
713
713
actor = Concurrent ::ProcessingActor .act(an_argument = 2 ) do |actor , number |
714
714
number ** 3
715
715
end
716
- # => #<Concurrent::ProcessingActor:0x000021 ... termination:pending>
716
+ # => #<Concurrent::ProcessingActor:0x000021 termination: pending>
717
717
actor.termination.value! # => 8
718
718
```
719
719
Let's receive some messages though.
@@ -725,12 +725,12 @@ add_2_messages = Concurrent::ProcessingActor.act do |actor|
725
725
a + b
726
726
end
727
727
end
728
- # => #<Concurrent::ProcessingActor:0x000024 ... termination:pending>
728
+ # => #<Concurrent::ProcessingActor:0x000022 termination: pending>
729
729
add_2_messages.tell_op 1
730
- # => #<Concurrent::Promises::Future:0x000027 pending>
730
+ # => #<Concurrent::Promises::Future:0x000023 pending>
731
731
add_2_messages.termination.resolved? # => false
732
732
add_2_messages.tell_op 3
733
- # => #<Concurrent::Promises::Future:0x000028 pending>
733
+ # => #<Concurrent::Promises::Future:0x000024 pending>
734
734
add_2_messages.termination.value! # => 4
735
735
```
736
736
@@ -750,13 +750,13 @@ slow_counter = -> (actor, count) do
750
750
end
751
751
end
752
752
end
753
- # => #<Proc:0x000029 @promises.in.md:638 (lambda)>
753
+ # => #<Proc:0x000025 @promises.in.md:638 (lambda)>
754
754
755
755
actor = Concurrent ::ProcessingActor .act_listening(
756
756
Concurrent ::Promises ::Channel .new (2 ),
757
757
0 ,
758
758
& slow_counter)
759
- # => #<Concurrent::ProcessingActor:0x00002a ... termination:pending>
759
+ # => #<Concurrent::ProcessingActor:0x000026 termination: pending>
760
760
```
761
761
762
762
Now we can create a producer which will push messages only when there is a
@@ -777,10 +777,10 @@ produce = -> receiver, i do
777
777
# do not continue
778
778
end
779
779
end
780
- # => #<Proc:0x00002d @promises.in.md:662 (lambda)>
780
+ # => #<Proc:0x000027 @promises.in.md:662 (lambda)>
781
781
782
782
Concurrent ::Promises .future(actor, 0 , & produce).run.wait!
783
- # => #<Concurrent::Promises::Future:0x00002e fulfilled with #<Concurrent::ProcessingActor:0x00002a @Mailbox=#<Concurrent::Promises::Channel:0x00002b capacity taken 2 of 2>, @Terminated=#<Concurrent::Promises::ResolvableFuture:0x00002c pending> termination:pending>>
783
+ # => #<Concurrent::Promises::Future:0x000028 fulfilled with #<Concurrent::ProcessingActor:0x000026 termination: pending>>
784
784
785
785
actor.termination.value! # => 45
786
786
```
@@ -792,17 +792,17 @@ actor.termination.value! # => 45
792
792
793
793
``` ruby
794
794
Concurrent ::Promises .future { do_stuff }
795
- # => #<Concurrent::Promises::Future:0x00002f pending>
795
+ # => #<Concurrent::Promises::Future:0x000029 pending>
796
796
```
797
797
798
798
## Parallel background processing
799
799
800
800
``` ruby
801
801
tasks = 4 .times.map { |i | Concurrent ::Promises .future(i) { |i | i* 2 } }
802
- # => [#<Concurrent::Promises::Future:0x000030 pending>,
803
- # #<Concurrent::Promises::Future:0x000031 pending>,
804
- # #<Concurrent::Promises::Future:0x000032 pending>,
805
- # #<Concurrent::Promises::Future:0x000033 pending>]
802
+ # => [#<Concurrent::Promises::Future:0x00002a pending>,
803
+ # #<Concurrent::Promises::Future:0x00002b pending>,
804
+ # #<Concurrent::Promises::Future:0x00002c pending>,
805
+ # #<Concurrent::Promises::Future:0x00002d pending>]
806
806
Concurrent ::Promises .zip(* tasks).value!
807
807
# => [0, 2, 4, 6]
808
808
```
@@ -856,11 +856,11 @@ Create the computer actor and send it 3 jobs.
856
856
857
857
``` ruby
858
858
computer = Concurrent ::Actor .spawn Computer , :computer
859
- # => #<Concurrent::Actor::Reference:0x000034 /computer (Computer)>
859
+ # => #<Concurrent::Actor::Reference:0x00002e /computer (Computer)>
860
860
results = 3 .times.map { computer.ask [:run , -> { sleep 0.01 ; :result }] }
861
- # => [#<Concurrent::Promises::Future:0x000035 pending>,
862
- # #<Concurrent::Promises::Future:0x000036 pending>,
863
- # #<Concurrent::Promises::Future:0x000037 pending>]
861
+ # => [#<Concurrent::Promises::Future:0x00002f pending>,
862
+ # #<Concurrent::Promises::Future:0x000030 pending>,
863
+ # #<Concurrent::Promises::Future:0x000031 pending>]
864
864
computer.ask(:status ).value! # => {:running_jobs=>3}
865
865
results.map(& :value! ) # => [:result, :result, :result]
866
866
```
@@ -892,7 +892,7 @@ body = lambda do |v|
892
892
new_v
893
893
end
894
894
end
895
- # => #<Proc:0x000038 @promises.in.md:765 (lambda)>
895
+ # => #<Proc:0x000032 @promises.in.md:765 (lambda)>
896
896
Concurrent ::Promises .future(0 , & body).run.value! # => 5
897
897
```
898
898
@@ -923,7 +923,7 @@ DB = Concurrent::Actor::Utils::AdHoc.spawn :db, data do |data|
923
923
data[message]
924
924
end
925
925
end
926
- # => #<Concurrent::Actor::Reference:0x000039 /db (Concurrent::Actor::Utils::AdHoc)>
926
+ # => #<Concurrent::Actor::Reference:0x000033 /db (Concurrent::Actor::Utils::AdHoc)>
927
927
928
928
concurrent_jobs = 11 .times.map do |v |
929
929
DB .
@@ -955,7 +955,7 @@ DB_POOL = Concurrent::Actor::Utils::Pool.spawn!('DB-pool', pool_size) do |index|
955
955
end
956
956
end
957
957
end
958
- # => #<Concurrent::Actor::Reference:0x00003a /DB-pool (Concurrent::Actor::Utils::Pool)>
958
+ # => #<Concurrent::Actor::Reference:0x000034 /DB-pool (Concurrent::Actor::Utils::Pool)>
959
959
960
960
concurrent_jobs = 11 .times.map do |v |
961
961
DB_POOL .
@@ -992,7 +992,7 @@ DB_INTERNAL_POOL = Concurrent::Array.new data
992
992
# "*********"]
993
993
994
994
max_tree = Concurrent ::Throttle .new 3
995
- # => #<Concurrent::Throttle:0x00003b capacity available 3 of 3>
995
+ # => #<Concurrent::Throttle:0x000035 capacity available 3 of 3>
996
996
997
997
futures = 11 .times.map do |i |
998
998
max_tree.
@@ -1017,9 +1017,9 @@ buffer and how to apply backpressure to slow down the queries.
1017
1017
require ' json'
1018
1018
1019
1019
channel = Concurrent ::Promises ::Channel .new 6
1020
- # => #<Concurrent::Promises::Channel:0x00003c capacity taken 0 of 6>
1020
+ # => #<Concurrent::Promises::Channel:0x000036 capacity taken 0 of 6>
1021
1021
cancellation, origin = Concurrent ::Cancellation .new
1022
- # => #<Concurrent::Cancellation:0x00003d pending>
1022
+ # => #<Concurrent::Cancellation:0x000037 pending>
1023
1023
1024
1024
def query_random_text (cancellation , channel )
1025
1025
Concurrent ::Promises .future do
@@ -1045,7 +1045,7 @@ end # => :query_random_text
1045
1045
1046
1046
words = [] # => []
1047
1047
words_throttle = Concurrent ::Throttle .new 1
1048
- # => #<Concurrent::Throttle:0x00003e capacity available 1 of 1>
1048
+ # => #<Concurrent::Throttle:0x000038 capacity available 1 of 1>
1049
1049
1050
1050
def count_words_in_random_text (cancellation , channel , words , words_throttle )
1051
1051
channel.pop_op.then do |response |
@@ -1067,16 +1067,16 @@ end # => :count_words_in_random_text
1067
1067
query_processes = 3 .times.map do
1068
1068
Concurrent ::Promises .future(cancellation, channel, & method(:query_random_text )).run
1069
1069
end
1070
- # => [#<Concurrent::Promises::Future:0x00003f pending>,
1071
- # #<Concurrent::Promises::Future:0x000040 pending>,
1072
- # #<Concurrent::Promises::Future:0x000041 pending>]
1070
+ # => [#<Concurrent::Promises::Future:0x000039 pending>,
1071
+ # #<Concurrent::Promises::Future:0x00003a pending>,
1072
+ # #<Concurrent::Promises::Future:0x00003b pending>]
1073
1073
1074
1074
word_counter_processes = 2 .times.map do
1075
1075
Concurrent ::Promises .future(cancellation, channel, words, words_throttle,
1076
1076
& method(:count_words_in_random_text )).run
1077
1077
end
1078
- # => [#<Concurrent::Promises::Future:0x000042 pending>,
1079
- # #<Concurrent::Promises::Future:0x000043 pending>]
1078
+ # => [#<Concurrent::Promises::Future:0x00003c pending>,
1079
+ # #<Concurrent::Promises::Future:0x00003d pending>]
1080
1080
1081
1081
sleep 0.05
1082
1082
```
@@ -1086,14 +1086,14 @@ Let it run for a while, then cancel it, and ensure that the runs were all fulfil
1086
1086
1087
1087
``` ruby
1088
1088
origin.resolve
1089
- # => #<Concurrent::Promises::ResolvableEvent:0x000044 resolved>
1089
+ # => #<Concurrent::Promises::ResolvableEvent:0x00003e resolved>
1090
1090
query_processes.map(& :wait! )
1091
- # => [#<Concurrent::Promises::Future:0x00003f fulfilled with nil>,
1092
- # #<Concurrent::Promises::Future:0x000040 fulfilled with nil>,
1093
- # #<Concurrent::Promises::Future:0x000041 fulfilled with nil>]
1091
+ # => [#<Concurrent::Promises::Future:0x000039 fulfilled with nil>,
1092
+ # #<Concurrent::Promises::Future:0x00003a fulfilled with nil>,
1093
+ # #<Concurrent::Promises::Future:0x00003b fulfilled with nil>]
1094
1094
word_counter_processes.map(& :wait! )
1095
- # => [#<Concurrent::Promises::Future:0x000042 fulfilled with nil>,
1096
- # #<Concurrent::Promises::Future:0x000043 fulfilled with nil>]
1095
+ # => [#<Concurrent::Promises::Future:0x00003c fulfilled with nil>,
1096
+ # #<Concurrent::Promises::Future:0x00003d fulfilled with nil>]
1097
1097
words # => [7, 7, 7, 7]
1098
1098
```
1099
1099
@@ -1114,24 +1114,24 @@ repeating_scheduled_task = -> interval, cancellation, task do
1114
1114
# Alternatively use chain to schedule always.
1115
1115
then { repeating_scheduled_task.call(interval, cancellation, task) }
1116
1116
end
1117
- # => #<Proc:0x000045 @promises.in.md:951 (lambda)>
1117
+ # => #<Proc:0x00003f @promises.in.md:951 (lambda)>
1118
1118
1119
1119
cancellation, origin = Concurrent ::Cancellation .new
1120
- # => #<Concurrent::Cancellation:0x000046 pending>
1120
+ # => #<Concurrent::Cancellation:0x000040 pending>
1121
1121
1122
1122
task = -> cancellation do
1123
1123
5 .times do
1124
1124
cancellation.check!
1125
1125
do_stuff
1126
1126
end
1127
1127
end
1128
- # => #<Proc:0x000047 @promises.in.md:962 (lambda)>
1128
+ # => #<Proc:0x000041 @promises.in.md:962 (lambda)>
1129
1129
1130
1130
result = Concurrent ::Promises .future(0.1 , cancellation, task, & repeating_scheduled_task).run
1131
- # => #<Concurrent::Promises::Future:0x000048 pending>
1131
+ # => #<Concurrent::Promises::Future:0x000042 pending>
1132
1132
sleep 0.03
1133
1133
origin.resolve
1134
- # => #<Concurrent::Promises::ResolvableEvent:0x000049 resolved>
1134
+ # => #<Concurrent::Promises::ResolvableEvent:0x000043 resolved>
1135
1135
result.result
1136
1136
# => [false,
1137
1137
# nil,
0 commit comments