Sha256: 5329a4451128504b5c0ecbf2832b003b34fddcb6088b52f4c2ce97b659eb9642

Contents?: true

Size: 834 Bytes

Versions: 9

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

# @api private
# @since 0.13.0
class Qonfig::Settings::Callbacks
  # @api private
  # @since 0.13.0
  include Enumerable

  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def initialize
    @callbacks = []
    @lock = Mutex.new
  end

  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def call
    thread_safe { callbacks.each(&:call) }
  end

  # @param callback [Proc, Qonfig::Settings::Callbacks, #call]
  # @return [void]
  #
  # @api private
  # @since 0.13.0
  def add(callback)
    thread_safe { callbacks << callback }
  end

  private

  # @return [Array<Proc>]
  #
  # @api private
  # @since 0.13.0
  attr_reader :callbacks

  # @return [Any]
  #
  # @api private
  # @since 0.14.0
  def thread_safe(&block)
    @lock.owned? ? yield : @lock.synchronize(&block)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
qonfig-0.20.0 lib/qonfig/settings/callbacks.rb
qonfig-0.19.1 lib/qonfig/settings/callbacks.rb
qonfig-0.19.0 lib/qonfig/settings/callbacks.rb
qonfig-0.18.1 lib/qonfig/settings/callbacks.rb
qonfig-0.18.0 lib/qonfig/settings/callbacks.rb
qonfig-0.17.0 lib/qonfig/settings/callbacks.rb
qonfig-0.16.0 lib/qonfig/settings/callbacks.rb
qonfig-0.15.0 lib/qonfig/settings/callbacks.rb
qonfig-0.14.0 lib/qonfig/settings/callbacks.rb