Sha256: f0d9472e74d07587c1206a5b429085ddced86042cd6bd0ab6d6a28b3a7fd5ce0

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

require "async"
require "async/semaphore"
require "timeout"

module Plumbing
  module Actor
    class Async
      attr_reader :target

      def initialize target
        @target = target
        @queue = []
        @semaphore = ::Async::Semaphore.new(1)
      end

      # Send the message to the target and wrap the result
      def send_message message_name, *args, &block
        task = @semaphore.async do
          @target.send message_name, *args, &block
        end
        Result.new(task)
      end

      Result = Data.define(:task) do
        def await
          Timeout.timeout(Plumbing::Actor.timeout) do
            task.wait
          end
        end
      end
      private_constant :Result
    end

    def self.timeout
      Plumbing.config.timeout
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.4.0 lib/plumbing/actor/async.rb