Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 20 lines (17 sloc) 0.541 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
require 'celluloid/fiber'

# Monkeypatch Thread to allow lazy access to its Celluloid::Mailbox
class Thread
  attr_accessor :uuid_counter, :uuid_limit

  # Retrieve the mailbox for the current thread or lazily initialize it
  def self.mailbox
    current[:mailbox] ||= Celluloid::Mailbox.new
  end

  # Receive a message either as an actor or through the local mailbox
  def self.receive(timeout = nil, &block)
    if Celluloid.actor?
      Celluloid.receive(timeout, &block)
    else
      mailbox.receive(timeout, &block)
    end
  end
end
Something went wrong with that request. Please try again.