lib/celluloid.rb in celluloid-0.12.0 vs lib/celluloid.rb in celluloid-0.12.1.pre

- old
+ new

@@ -4,12 +4,16 @@ require 'set' module Celluloid extend self # expose all instance methods as singleton methods - SHUTDOWN_TIMEOUT = 120 # How long actors have to terminate + # How long actors have to terminate + SHUTDOWN_TIMEOUT = 120 + # Warning message added to Celluloid objects accessed outside their actors + BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT " + class << self attr_accessor :logger # Thread-safe logger class attr_accessor :task_class # Default task type to use def included(klass) @@ -192,19 +196,28 @@ end # These are methods we don't want added to the Celluloid singleton but to be # defined on all classes that use Celluloid module InstanceMethods - # Obtain the Ruby object the actor is wrapping. This should ONLY be used - # for a limited set of use cases like runtime metaprogramming. Interacting - # directly with the wrapped object foregoes any kind of thread safety that + # Obtain the bare Ruby object the actor is wrapping. This is useful for + # only a limited set of use cases like runtime metaprogramming. Interacting + # directly with the bare object foregoes any kind of thread safety that # Celluloid would ordinarily provide you, and the object is guaranteed to # be shared with at least the actor thread. Tread carefully. - def wrapped_object; self; end + # + # Bare objects can be identified via #inspect output: + # + # >> actor + # => #<Celluloid::Actor(Foo:0x3fefcb77c194)> + # >> actor.bare_object + # => #<WARNING: BARE CELLULOID OBJECT (Foo:0x3fefcb77c194)> + # + def bare_object; self; end + alias_method :wrapped_object, :bare_object def inspect - str = "#<Celluloid::Actor(#{self.class}:0x#{object_id.to_s(16)})" + str = "#<#{Celluloid::BARE_OBJECT_WARNING_MESSAGE}(#{self.class}:0x#{object_id.to_s(16)})" ivars = instance_variables.map do |ivar| "#{ivar}=#{instance_variable_get(ivar).inspect}" end str << " " << ivars.join(' ') unless ivars.empty? @@ -237,14 +250,9 @@ # # The following methods are available on both the Celluloid singleton and # directly inside of all classes that include Celluloid # - - # Is this actor alive? - def alive? - Thread.current[:actor].alive? - end # Raise an exception in caller context, but stay running def abort(cause) cause = case cause when String then RuntimeError.new(cause)