Class: Celluloid::SyncCall

### Home Classes Methods

### In Files

- lib/celluloid/calls.rb

### Parent

Celluloid::Call

### Methods

- ::new
- #cleanup
- #dispatch
- #respond
- #response
- #value
- #wait

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::AbortError
- Celluloid::AbstractProxy
- Celluloid::Actor
- Celluloid::Actor::Sleeper
- Celluloid::ActorProxy
- Celluloid::ActorSystem
- Celluloid::AsyncCall
- Celluloid::AsyncProxy
- Celluloid::BlockCall
- Celluloid::BlockProxy
- Celluloid::BlockResponse
- Celluloid::CPUCounter
- Celluloid::Call
- Celluloid::CallChain
- Celluloid::Cell
- Celluloid::Cell::ExitHandler
- Celluloid::CellProxy
- Celluloid::ClassMethods
- Celluloid::Condition
- Celluloid::Condition::Waiter
- Celluloid::ConditionError
- Celluloid::DeadTaskError
- Celluloid::ErrorResponse
- Celluloid::EventedMailbox
- Celluloid::ExitEvent
- Celluloid::FSM
- Celluloid::FSM::ClassMethods
- Celluloid::FSM::State
- Celluloid::FSM::UnattachedError
- Celluloid::FiberStackError
- Celluloid::Future
- Celluloid::Future::Result
- Celluloid::FutureProxy
- Celluloid::Handler
- Celluloid::Handlers
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::InstanceMethods
- Celluloid::InternalPool
- Celluloid::LinkingRequest
- Celluloid::LinkingResponse
- Celluloid::Links
- Celluloid::LogEvent
- Celluloid::Logger
- Celluloid::Logger::WithBacktrace
- Celluloid::Mailbox
- Celluloid::MailboxDead
- Celluloid::MailboxShutdown
- Celluloid::Method
- Celluloid::NamingRequest
- Celluloid::NotTaskError
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::PoolManager
- Celluloid::Probe
- Celluloid::Properties
- Celluloid::Receiver
- Celluloid::Receivers
- Celluloid::Registry
- Celluloid::Response
- Celluloid::ResumableError
- Celluloid::RingBuffer
- Celluloid::SignalConditionRequest
- Celluloid::Signals
- Celluloid::StackDump
- Celluloid::StackDump::ActorState
- Celluloid::StackDump::CellState
- Celluloid::StackDump::DisplayBacktrace
- Celluloid::StackDump::TaskState
- Celluloid::StackDump::ThreadState
- Celluloid::SuccessResponse
- Celluloid::SupervisionGroup
- Celluloid::SupervisionGroup::Member
- Celluloid::Supervisor
- Celluloid::SyncCall
- Celluloid::SyncProxy
- Celluloid::SystemEvent
- Celluloid::Task
- Celluloid::Task::TerminatedError
- Celluloid::Task::TimeoutError
- Celluloid::TaskFiber
- Celluloid::TaskSet
- Celluloid::TaskThread
- Celluloid::TerminationRequest
- Celluloid::Thread
- Celluloid::ThreadHandle
- Celluloid::UUID
- org
- org::jruby
- org::jruby::ext
- org::jruby::ext::fiber
- org::jruby::ext::fiber::ThreadFiber
- Bar
- Baz
- Blocker
- ExampleActorClass
- ExampleCrash
- ExampleMailbox
- ExampleProxy
- ExampleTask
- Fiber
- Foo
- MockActor
- Object
- Thread

No matching classes.

# Celluloid::SyncCall

Synchronous calls wait for a response

### Attributes

chain_id[R]
sender[R]
task[R]

### Public Class Methods

new(sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = CallChain.current_id) click to toggle source

    # File lib/celluloid/calls.rb, line 53
    def initialize(sender, method, arguments = [], block = nil, task = Thread.current[:celluloid_task], chain_id = CallChain.current_id)
      super(method, arguments, block)

      @sender   = sender
      @task     = task
      @chain_id = chain_id || Celluloid.uuid
    end

### Public Instance Methods

cleanup() click to toggle source

    # File lib/celluloid/calls.rb, line 78
    def cleanup
      exception = DeadActorError.new("attempted to call a dead actor")
      respond ErrorResponse.new(self, exception)
    end

dispatch(obj) click to toggle source

    # File lib/celluloid/calls.rb, line 61
    def dispatch(obj)
      CallChain.current_id = @chain_id
      result = super(obj)
      respond SuccessResponse.new(self, result)
    rescue Exception => ex
      # Exceptions that occur during synchronous calls are reraised in the
      # context of the sender
      respond ErrorResponse.new(self, ex)

      # Aborting indicates a protocol error on the part of the sender
      # It should crash the sender, but the exception isn't reraised
      # Otherwise, it's a bug in this actor and should be reraised
      raise unless ex.is_a?(AbortError)
    ensure
      CallChain.current_id = nil
    end

respond(message) click to toggle source

    # File lib/celluloid/calls.rb, line 83
    def respond(message)
      @sender << message
    end

response() click to toggle source

    # File lib/celluloid/calls.rb, line 87
    def response
      Celluloid.suspend(:callwait, self)
    end

value() click to toggle source

    # File lib/celluloid/calls.rb, line 91
    def value
      response.value
    end

wait() click to toggle source

    # File lib/celluloid/calls.rb, line 95
    def wait
      loop do
        message = Celluloid.mailbox.receive do |msg|
          msg.respond_to?(:call) and msg.call == self
        end

        if message.is_a?(SystemEvent)
          Thread.current[:celluloid_actor].handle_system_event(message)
        else
          # FIXME: add check for receiver block execution
          if message.respond_to?(:value)
            # FIXME: disable block execution if on :sender and (exclusive or outside of task)
            # probably now in Call
            break message
          else
            message.dispatch
          end
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.