Sha256: 09aa0a8c05edbd71d118295404e0f5b7e1e34c4c4d38058aed94bef85f9c8609

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

module Celluloid
  module Proxy
    # A proxy which sends asynchronous calls to an actor
    class Async < Abstract
      attr_reader :mailbox

      # Used for reflecting on proxy objects themselves
      def __class__
        Proxy::Async
      end

      def initialize(mailbox, klass)
        @mailbox = mailbox
        @klass = klass
      end

      def inspect
        "#<Celluloid::Proxy::Async(#{@klass})>"
      end

      def method_missing(meth, *args, &block)
        if @mailbox == ::Thread.current[:celluloid_mailbox]
          args.unshift meth
          meth = :__send__
        end

        if block_given?
          # FIXME: nicer exception
          fail "Cannot use blocks with async yet"
        end

        @mailbox << Call::Async.new(meth, args, block)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celluloid-0.17.0 lib/celluloid/proxy/async.rb