Class: Celluloid::Internals::Receivers

### Home Classes Methods

### In Files

- lib/celluloid/internals/receivers.rb

### Parent

Object

### Methods

- ::new
- #handle_message
- #receive

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# Celluloid::Internals::Receivers

Allow methods to directly interact with the actor protocol

### Public Class Methods

new(timers) click to toggle source

    # File lib/celluloid/internals/receivers.rb, line 8
    def initialize(timers)
      @receivers = Set.new
      @timers = timers
    end

### Public Instance Methods

handle_message(message) click to toggle source

Handle incoming messages

    # File lib/celluloid/internals/receivers.rb, line 33
    def handle_message(message)
      receiver = @receivers.find { |r| r.match(message) }
      return unless receiver

      @receivers.delete receiver
      receiver.timer.cancel if receiver.timer
      receiver.resume message
      message
    end

receive(timeout = nil, &block) click to toggle source

Receive an asynchronous message

    # File lib/celluloid/internals/receivers.rb, line 14
    def receive(timeout = nil, &block)
      if Celluloid.exclusive?
        Celluloid.mailbox.receive(timeout, &block)
      else
        receiver = Receiver.new block

        if timeout
          receiver.timer = @timers.after(timeout) do
            @receivers.delete receiver
            receiver.resume
          end
        end

        @receivers << receiver
        Task.suspend :receiving
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.