File: links.rb

package info (click to toggle)
ruby-celluloid-essentials 0.20.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 240 kB
  • sloc: ruby: 1,084; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 811 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Celluloid
  module Internals
    # Linked actors send each other system events
    class Links
      include Enumerable

      def initialize
        @links = {}
      end

      # Add an actor to the current links
      def <<(actor)
        @links[actor.mailbox.address] = actor
      end

      # Do links include the given actor?
      def include?(actor)
        @links.key? actor.mailbox.address
      end

      # Remove an actor from the links
      def delete(actor)
        @links.delete actor.mailbox.address
      end

      # Iterate through all links
      def each
        @links.each { |_, actor| yield(actor) }
      end

      # Generate a string representation
      def inspect
        links = map(&:inspect).join(",")
        "#<#{self.class}[#{links}]>"
      end
    end
  end
end