Sha256: e657feeaa71459142a575030b382efc3b50ddd6b02e20ee51cf27a3539c006f2

Contents?: true

Size: 904 Bytes

Versions: 15

Compression:

Stored size: 904 Bytes

Contents

module Concurrent
  module Actor
    module Behaviour

      # Links the actor to other actors and sends events to them,
      # like: `:terminated`, `:paused`, errors, etc
      class Linking < Abstract
        def initialize(core, subsequent)
          super core, subsequent
          @linked = Set.new
        end

        def on_envelope(envelope)
          case envelope.message
          when :link
            link envelope.sender
          when :unlink
            unlink envelope.sender
          else
            pass envelope
          end
        end

        def link(ref)
          @linked.add(ref)
          true
        end

        def unlink(ref)
          @linked.delete(ref)
          true
        end

        def on_event(event)
          @linked.each { |a| a << event }
          @linked.clear if event == :terminated
          super event
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
concurrent-ruby-0.7.0 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-x86_64-linux lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-x86-solaris-2.11 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-x86-mingw32 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-x86-linux lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-x64-mingw32 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0-java lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x86_64-linux lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x86_64-darwin-13 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x86-solaris-2.11 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x86-mingw32 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x86-linux lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-x64-mingw32 lib/concurrent/actor/behaviour/linking.rb
concurrent-ruby-0.7.0.rc2-java lib/concurrent/actor/behaviour/linking.rb