Sha256: 23a5e14ea6e688a2b9e7a7fa19b23209447b739bec02c63a9313b2005098317a

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module Celluloid
  class Group
    attr_accessor :group

    def initialize
      @mutex = Mutex.new
      @group = []
      @running = true
    end

    def assert_active
      fail Celluloid::NotActive unless active?
    end

    def assert_inactive
      return unless active?
      if RUBY_PLATFORM == "java"
        Celluloid.logger.warn "Group is still active"
      else
        fail Celluloid::StillActive
      end
    end

    def each
      to_a.each { |thread| yield thread }
    end

    def to_a
      res = nil
      @mutex.synchronize { res = @group.dup }
      res
    end

    def purge(thread)
      @mutex.synchronize do
        @group.delete(thread)
        thread.kill rescue nil
      end
    end

    def each_actor(&block)
      to_a.lazy.select { |t| t[:celluloid_role] == :actor }.each(&block)
    end

    def active?
      @running
    end

    def get
      fail NotImplementedError
    end

    def create
      fail NotImplementedError
    end

    def shutdown
      fail NotImplementedError
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
celluloid-0.17.3 lib/celluloid/group.rb
celluloid-0.17.2 lib/celluloid/group.rb
celluloid-0.17.1.2 lib/celluloid/group.rb
celluloid-0.17.1.1 lib/celluloid/group.rb
celluloid-0.17.1 lib/celluloid/group.rb