Sha256: ce9566c95ec056c69ae71f9522f631017180c8f8180279f6465ab2b7c48ee847

Contents?: true

Size: 1.96 KB

Versions: 8

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require_relative "array/entities"

module ConvenientService
  module Support
    class Cache
      module Entities
        module Caches
          class ThreadSafeArray < Caches::Array
            ##
            # @return [void]
            #
            def initialize(array = [])
              super

              @lock = ::Mutex.new
            end

            ##
            # @return [Boolean]
            #
            def empty?(...)
              @lock.synchronize { super }
            end

            ##
            # @return [Boolean]
            #
            def exist?(...)
              @lock.synchronize { super }
            end

            ##
            # @return [Object] Can be any type.
            #
            def read(...)
              @lock.synchronize { super }
            end

            ##
            # @return [Object] Can be any type.
            #
            def write(...)
              @lock.synchronize { super }
            end

            ##
            # @return [Object] Can be any type.
            #
            def fetch(...)
              @lock.synchronize { super }
            end

            ##
            # @return [Object] Can be any type.
            #
            def delete(...)
              @lock.synchronize { super }
            end

            ##
            # @return [ConvenientService::Support::Cache::Entities::Caches::Array]
            #
            def clear(...)
              @lock.synchronize { super }
            end

            ##
            # @internal
            #   `scope` method from parent delegates to thread-safe `fetch`, that is why child `scope` method does NOT require additional synchronization.
            #
            # def scope(...)
            #   # ...
            # end
            ##

            ##
            # @note NOT thread-safe.
            #
            # def ==(other)
            #   # ...
            # end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.19.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.18.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.17.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.16.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.15.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.14.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb
convenient_service-0.13.0 lib/convenient_service/support/cache/entities/caches/thread_safe_array.rb