• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-concurrency / concurrent-ruby / #2764

08 Dec 2014 03:40PM UTC coverage: 91.388% (-0.4%) from 91.753%
#2764

push

jdantonio
Merge pull request #201 from rkday/fallback_handling

Posting to a shutdown thread pool - JRuby consistency and better naming

18 of 26 new or added lines in 5 files covered. (69.23%)

212 existing lines in 36 files now uncovered.

2812 of 3077 relevant lines covered (91.39%)

369.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.37
/lib/concurrent/actor.rb
1
require 'concurrent/configuration'
1✔
2
require 'concurrent/executor/serialized_execution'
1✔
3
require 'concurrent/ivar'
1✔
4
require 'concurrent/logging'
1✔
5
require 'concurrent/atomic/synchronization'
1✔
6

7
module Concurrent
1✔
8
  # TODO https://github.com/celluloid/celluloid/wiki/Supervision-Groups ?
9
  # TODO Remote actors using DRb
10
  # TODO IO interoperation
11
  # TODO un/become
12

13
  # TODO doc
14
  # - what happens if I try to supervise using a normal Context?
15
  # - how to change behaviours
16
  # - how to implement custom restarting?
17
  # - pool for io operations using different executor
18
  # - document guaranteed ordering
19

20
  # {include:file:doc/actor/main.md}
21
  module Actor
1✔
22

23
    require 'concurrent/actor/type_check'
1✔
24
    require 'concurrent/actor/errors'
1✔
25
    require 'concurrent/actor/public_delegations'
1✔
26
    require 'concurrent/actor/internal_delegations'
1✔
27
    require 'concurrent/actor/envelope'
1✔
28
    require 'concurrent/actor/reference'
1✔
29
    require 'concurrent/actor/core'
1✔
30
    require 'concurrent/actor/behaviour'
1✔
31
    require 'concurrent/actor/context'
1✔
32

33
    require 'concurrent/actor/default_dead_letter_handler'
1✔
34
    require 'concurrent/actor/root'
1✔
35
    require 'concurrent/actor/utils'
1✔
36

37
    # @return [Reference, nil] current executing actor if any
38
    def self.current
1✔
39
      Thread.current[:__current_actor__]
2,959✔
40
    end
41

42
    @root = Delay.new do
1✔
43
      Core.new(parent: nil, name: '/', class: Root, initialized: ivar = IVar.new).reference.tap do
1✔
44
        ivar.no_error!
1✔
45
      end
46
    end
47

48
    # A root actor, a default parent of all actors spawned outside an actor
49
    def self.root
1✔
50
      @root.value!
444✔
51
    end
52

53
    # Spawns a new actor.
54
    #
55
    # @example simple
56
    #   Actor.spawn(AdHoc, :ping1) { -> message { message } }
57
    #
58
    # @example complex
59
    #   Actor.spawn name:     :ping3,
60
    #                 class:    AdHoc,
61
    #                 args:     [1]
62
    #                 executor: Concurrent.configuration.global_task_pool do |add|
63
    #     lambda { |number| number + add }
64
    #   end
65
    #
66
    # @param block for context_class instantiation
67
    # @param args see {.spawn_optionify}
68
    # @return [Reference] never the actual actor
69
    def self.spawn(*args, &block)
1✔
70
      if Actor.current
394✔
71
        Core.new(spawn_optionify(*args).merge(parent: Actor.current), &block).reference
254✔
72
      else
73
        root.ask([:spawn, spawn_optionify(*args), block]).value!
140✔
74
      end
75
    end
76

77
    # as {.spawn} but it'll raise when Actor not initialized properly
78
    def self.spawn!(*args, &block)
1✔
79
      spawn(spawn_optionify(*args).merge(initialized: ivar = IVar.new), &block).tap { ivar.no_error! }
10✔
80
    end
81

82
    # @overload spawn_optionify(context_class, name, *args)
83
    #   @param [AbstractContext] context_class to be spawned
84
    #   @param [String, Symbol] name of the instance, it's used to generate the {Core#path} of the actor
85
    #   @param args for context_class instantiation
86
    # @overload spawn_optionify(opts)
87
    #   see {Core#initialize} opts
88
    def self.spawn_optionify(*args)
1✔
89
      if args.size == 1 && args.first.is_a?(Hash)
399✔
90
        args.first
393✔
91
      else
92
        { class: args[0],
6✔
93
          name:  args[1],
94
          args:  args[2..-1] }
95
      end
96
    end
97

98
    # call this to disable experimental warning
99
    def self.i_know_it_is_experimental!
1✔
UNCOV
100
      warn 'Method Actor.i_know_it_is_experimental! is deprecated. The Actors are no longer experimental.'
×
101
    end
102
  end
103
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc