File: group.rb

package info (click to toggle)
ruby-celluloid 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 7,579; makefile: 10
file content (71 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Celluloid
  class Group
    attr_accessor :group

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

    def assert_active
      raise Celluloid::NotActive unless active?
    end

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

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

    def forked?
      @pid != $PROCESS_ID
    end

    def to_a
      return [] if forked?
      res = nil
      @mutex.synchronize { res = @group.dup }
      res
    end

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

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

    def active?
      @running
    end

    def get
      raise NotImplementedError
    end

    def create
      raise NotImplementedError
    end

    def shutdown
      raise NotImplementedError
    end
  end
end