Sha256: db94387fa72fcc44905d7751cd29b2ec86e6b58e7e5ee758ab6f94df8e5c46f1

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require "concurrent"

module NSA
  module Statsd
    module AsyncPublisher
      include ::NSA::Statsd::Publisher

      def async_statsd_count(key, sample_rate = 1, &block)
        return unless sample_rate == 1 || rand < sample_rate

        ::Concurrent::Promise.execute(&block).then do |value|
          statsd_count(key, value)
        end
      end

      def async_statsd_gauge(key, sample_rate = 1, &block)
        return unless sample_rate == 1 || rand < sample_rate

        ::Concurrent::Promise.execute(&block).then do |value|
          statsd_gauge(key, value)
        end
      end

      def async_statsd_set(key, sample_rate = 1, &block)
        return unless sample_rate == 1 || rand < sample_rate

        ::Concurrent::Promise.execute(&block).then do |value|
          statsd_set(key, value)
        end
      end

      def async_statsd_time(key, sample_rate = 1, &block)
        return unless sample_rate == 1 || rand < sample_rate

        ::Concurrent::Future.execute do
          statsd_time(key, &block)
        end
      end

      def async_statsd_timing(key, sample_rate = 1, &block)
        return unless sample_rate == 1 || rand < sample_rate

        ::Concurrent::Promise.execute(&block).then do |value|
          statsd_timing(key, value)
        end
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nsa-0.3.0 lib/nsa/statsd/async_publisher.rb
nsa-0.2.8 lib/nsa/statsd/async_publisher.rb
nsa-0.2.7 lib/nsa/statsd/async_publisher.rb
nsa-0.2.5 lib/nsa/statsd/async_publisher.rb
nsa-0.2.4 lib/nsa/statsd/async_publisher.rb
nsa-0.2.3 lib/nsa/statsd/async_publisher.rb
nsa-0.2.1 lib/nsa/statsd/async_publisher.rb