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

jdantonio / concurrent-ruby / #748

24 Apr 2014 12:31AM UTC coverage: 78.31% (-19.5%) from 97.805%
#748

push

jdantonio
Attempting to fix a brittle test of Concurrent::timer.

1928 of 2462 relevant lines covered (78.31%)

409.47 hits per line

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

63.64
/lib/concurrent/actor/actor_context.rb
1
require 'concurrent/actor/simple_actor_ref'
1✔
2

3
module Concurrent
1✔
4

5
  # Actor-based concurrency is all the rage in some circles. Originally described in
6
  # 1973, the actor model is a paradigm for creating asynchronous, concurrent objects
7
  # that is becoming increasingly popular. Much has changed since actors were first
8
  # written about four decades ago, which has led to a serious fragmentation within
9
  # the actor community. There is *no* universally accepted, strict definition of
10
  # "actor" and actor implementations differ widely between languages and libraries.
11
  # 
12
  # A good definition of "actor" is:
13
  # 
14
  #   An independent, concurrent, single-purpose, computational entity that communicates exclusively via message passing.
15
  #
16
  # The actor framework in this library is heavily influenced by the Akka toolkit,
17
  # with additional inspiration from Erlang and Scala. Unlike many of the abstractions
18
  # in this library, `ActorContext` takes an *object-oriented* approach to asynchronous
19
  # concurrency, rather than a *functional programming* approach.
20
  #
21
  # Creating an actor class is achieved by including the `ActorContext` module
22
  # within a standard Ruby class. One `ActorContext` is mixed in, however, everything
23
  # changes. Objects of the class can no longer be instanced with the `#new` method.
24
  # Instead, the various factor methods, such as `#spawn`, must be used. These factory
25
  # methods do not return direct references to the actor object. Instead they return
26
  # objects of one of the `ActorRef` subclasses. The `ActorRef` objects encapsulate
27
  # actor objects. This encapsulation is necessary to prevent synchronous method calls
28
  # froom being made against the actors. It also allows the messaging and lifecycle
29
  # behavior to be implemented within the `ActorRef` subclasses, allowing for better
30
  # separation of responsibility.
31
  #
32
  # @see Concurrent::ActorRef
33
  #
34
  # @see http://akka.io/
35
  # @see http://www.erlang.org/doc/getting_started/conc_prog.html
36
  # @see http://www.scala-lang.org/api/current/index.html#scala.actors.Actor
37
  #
38
  # @see http://doc.akka.io/docs/akka/snapshot/general/supervision.html#What_Restarting_Means What Restarting Means
39
  # @see http://doc.akka.io/docs/akka/snapshot/general/supervision.html#What_Lifecycle_Monitoring_Means What Lifecycle Monitoring Means
40
  module ActorContext
1✔
41

42
    # Callback method called by the `ActorRef` which encapsulates the actor instance.
43
    def on_start
1✔
44
    end
45

46
    # Callback method called by the `ActorRef` which encapsulates the actor instance.
47
    def on_shutdown
1✔
48
    end
49

50
    # Callback method called by the `ActorRef` which encapsulates the actor instance.
51
    #
52
    # @param [Time] time the date/time at which the error occurred
53
    # @param [Array] message the message that caused the error
54
    # @param [Exception] exception the exception object that was raised
55
    def on_error(time, message, exception)
1✔
56
    end
57

58
    def self.included(base)
1✔
59

60
      class << base
×
61

62
        # Create a single, unregistered actor. The actor will run on its own, dedicated
63
        # thread. The thread will be started the first time a message is post to the actor.
64
        # Should the thread ever die it will be restarted the next time a message is post.
65
        #
66
        # @param [Hash] opts the options defining actor behavior
67
        # @option opts [Array] :args (`nil`) arguments to be passed to the actor constructor
68
        #
69
        # @return [SimpleActorRef] the `ActorRef` encapsulating the actor
70
        def spawn(opts = {})
×
71
          args = opts.fetch(:args, [])
×
72
          Concurrent::SimpleActorRef.new(self.new(*args), opts)
×
73
        end
74
      end
75
    end
76
  end
77
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