module Persistent💎::ConcurrentRubySupport

Simple module that attempts to load concurrent-ruby, and then stores the result for quick lookup This way we take care of loading concurrent-ruby ONLY when the library client asks us to, thus not bloating applications that don't need concurrent-ruby loaded but still having a great user experience

Constants

REQUIRE_MUTEX

Public Class Methods

ensure_concurrent_ruby_loaded() click to toggle source
# File lib/persistent_dmnd/concurrent_ruby_support.rb, line 44
def ensure_concurrent_ruby_loaded
  loaded = @concurrent_loaded

  if loaded == :success
    return true
  elsif loaded == :failure
    raise_no_concurrent_ruby
  end

  begin
    REQUIRE_MUTEX.synchronize do # Avoid require races
      require 'concurrent'
    end
    mark_as_success
    true
  rescue LoadError
    mark_as_failure
    raise_no_concurrent_ruby
  end
end

Private Class Methods

mark_as_failure() click to toggle source
# File lib/persistent_dmnd/concurrent_ruby_support.rb, line 78
def mark_as_failure
  @concurrent_loaded = :failure
end
mark_as_success() click to toggle source

The following methods are only for internal and test usage. Please do not use them :)

# File lib/persistent_dmnd/concurrent_ruby_support.rb, line 74
def mark_as_success
  @concurrent_loaded = :success
end
raise_no_concurrent_ruby() click to toggle source
# File lib/persistent_dmnd/concurrent_ruby_support.rb, line 67
def raise_no_concurrent_ruby
  raise(NotImplementedError,
        'concurrent-ruby gem is not available, please install it in order to use #to_concurrent and #to_concurrent_* methods')
end
reset_state() click to toggle source
# File lib/persistent_dmnd/concurrent_ruby_support.rb, line 82
def reset_state
  @concurrent_loaded = nil
end