Sha256: 813eeb7c15851ed14bc3dd9cca9477f9b32da181248753da0963b23892087f89

Contents?: true

Size: 1.49 KB

Versions: 159

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module Seahorse
  module Client
    class AsyncResponse

      def initialize(options = {})
        @response = Response.new(context: options[:context])
        @stream = options[:stream]
        @stream_mutex = options[:stream_mutex]
        @close_condition = options[:close_condition]
        @sync_queue = options[:sync_queue]
      end

      def context
        @response.context
      end

      def error
        @response.error
      end

      def on(range, &block)
        @response.on(range, &block)
        self
      end

      def on_complete(&block)
        @response.on_complete(&block)
        self
      end

      def wait
        if error && context.config.raise_response_errors
          raise error
        elsif @stream
          # have a sync signal that #signal can be blocked on
          # else, if #signal is called before #wait
          # will be waiting for a signal never arrives
          @sync_queue << "sync_signal"
          # now #signal is unlocked for
          # signaling close condition when ready
          @stream_mutex.synchronize {
            @close_condition.wait(@stream_mutex)
          }
          @response
        end
      end

      def join!
        if error && context.config.raise_response_errors
          raise error
        elsif @stream
          # close callback is waiting
          # for the "sync_signal"
          @sync_queue << "sync_signal"
          @stream.close
          @response
        end
      end

    end
  end
end

Version data entries

159 entries across 159 versions & 1 rubygems

Version Path
aws-sdk-core-3.192.1 lib/seahorse/client/async_response.rb
aws-sdk-core-3.192.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.6 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.5 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.4 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.3 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.2 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.1 lib/seahorse/client/async_response.rb
aws-sdk-core-3.191.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.190.3 lib/seahorse/client/async_response.rb
aws-sdk-core-3.190.2 lib/seahorse/client/async_response.rb
aws-sdk-core-3.190.1 lib/seahorse/client/async_response.rb
aws-sdk-core-3.190.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.189.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.188.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.187.1 lib/seahorse/client/async_response.rb
aws-sdk-core-3.187.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.186.0 lib/seahorse/client/async_response.rb
aws-sdk-core-3.185.2 lib/seahorse/client/async_response.rb
aws-sdk-core-3.185.1 lib/seahorse/client/async_response.rb