File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ module Concurrent
2+ module Actor
3+ module Utils
4+ require 'concurrent/actor/utils/broadcast'
5+ end
6+ end
7+ end
Original file line number Diff line number Diff line change 1+ require 'set'
2+
3+ module Concurrent
4+ module Actor
5+ module Utils
6+ class Broadcast < Context
7+
8+ def initialize
9+ @receivers = Set . new
10+ end
11+
12+ def on_message ( message )
13+ case message
14+ when :subscribe
15+ @receivers . add envelope . sender
16+ when :unsubscribe
17+ @receivers . delete envelope . sender
18+ when :subscribed?
19+ @receivers . include? envelope . sender
20+ else
21+ @receivers . each { |r | r << message }
22+ end
23+ end
24+
25+ # override to define different behaviour, filtering etc
26+ def receivers
27+ @receivers
28+ end
29+ end
30+ end
31+ end
32+ end
You can’t perform that action at this time.
0 commit comments