Sha256: 8219374e7e65371446a1f0ad7a142b41e4c52fb84a3a814f6e476950645e83f3

Contents?: true

Size: 722 Bytes

Versions: 4

Compression:

Stored size: 722 Bytes

Contents

module Asynchronic
  module DataStore
    class InMemory

      include Helper

      def initialize(hash={})
        @hash = {}
        @mutex = Mutex.new
        self.class.connections[object_id] = self
      end

      def [](key)
        @hash[key.to_s]
      end

      def []=(key, value)
        @mutex.synchronize { @hash[key.to_s] = value }
      end

      def delete(key)
        @hash.delete key.to_s
      end

      def keys
        @hash.keys.map { |k| Key.new k }
      end

      def connection_args
        [object_id]
      end

      def self.connect(object_id)
        connections[object_id]
      end

      private

      def self.connections
        @connections ||= {}
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
asynchronic-1.2.0 lib/asynchronic/data_store/in_memory.rb
asynchronic-1.1.1 lib/asynchronic/data_store/in_memory.rb
asynchronic-1.1.0 lib/asynchronic/data_store/in_memory.rb
asynchronic-1.0.0 lib/asynchronic/data_store/in_memory.rb