Skip to content

Commit f409578

Browse files
committed
Add Broadcast doc
1 parent 05b8492 commit f409578

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/concurrent/actor/utils/broadcast.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ module Concurrent
44
module Actor
55
module Utils
66

7-
# TODO doc
7+
# Allows to build pub/sub easily.
8+
# @example news
9+
# news_channel = Concurrent::Actor::Utils::Broadcast.spawn :news
10+
11+
# 2.times do |i|
12+
# Concurrent::Actor::Utils::AdHoc.spawn "listener-#{i}" do
13+
# news_channel << :subscribe
14+
# -> message { puts message }
15+
# end
16+
# end
17+
#
18+
# news_channel << 'Ruby rocks!'
19+
# # prints: 'Ruby rocks!' twice
820
class Broadcast < Context
921

1022
def initialize
@@ -34,6 +46,7 @@ def filtered_receivers
3446
@receivers
3547
end
3648
end
49+
3750
end
3851
end
3952
end

0 commit comments

Comments
 (0)