Skip to content

Commit a9f07b9

Browse files
committed
Move AdHoc to utils
1 parent 24ce228 commit a9f07b9

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

doc/actor/celluloid_benchmark.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def counting(count, ivar)
4848
b.report(format('%5d %4d %s', ADD_TO*counts_size, adders_size, 'concurrent')) do
4949
counts = Array.new(counts_size) { [0, Concurrent::IVar.new] }
5050
adders = Array.new(adders_size) do |i|
51-
Concurrent::Actor::AdHoc.spawn("adder#{i}") do
51+
Concurrent::Actor::Utils::AdHoc.spawn("adder#{i}") do
5252
lambda do |(count, ivar)|
5353
if count < ADD_TO
5454
adders[(i+1) % adders_size].tell [count+1, ivar]

lib/concurrent/actor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module Actor
2626

2727
require 'concurrent/actor/default_dead_letter_handler'
2828
require 'concurrent/actor/root'
29-
require 'concurrent/actor/ad_hoc'
29+
require 'concurrent/actor/utils'
3030

3131
# @return [Reference, nil] current executing actor if any
3232
def self.current

lib/concurrent/actor/ad_hoc.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/concurrent/actor/utills.rb renamed to lib/concurrent/actor/utils.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Concurrent
22
module Actor
33
module Utils
44
require 'concurrent/actor/utils/broadcast'
5+
require 'concurrent/actor/utils/ad_hoc'
56
end
67
end
78
end

lib/concurrent/actor/utils/ad_hoc.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Concurrent
2+
module Actor
3+
module Utils
4+
# Allows quick creation of actors with behaviour defined by blocks.
5+
# @example ping
6+
# AdHoc.spawn :forward, an_actor do |where|
7+
# # this block has to return proc defining #on_message behaviour
8+
# -> message { where.tell message }
9+
# end
10+
class AdHoc < Context
11+
def initialize(*args, &initializer)
12+
@on_message = Type! initializer.call(*args), Proc
13+
end
14+
15+
def on_message(message)
16+
instance_exec message, &@on_message
17+
end
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)