summaryrefslogtreecommitdiff
path: root/lib/storage.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/storage.rb')
-rw-r--r--lib/storage.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/storage.rb b/lib/storage.rb
new file mode 100644
index 0000000..57b2548
--- /dev/null
+++ b/lib/storage.rb
@@ -0,0 +1,30 @@
+class Storage
+ def initialize(storage: {})
+ @storage = storage
+ @mutex = Mutex.new
+ end
+
+ def key?(key)
+ with_lock { @storage.key?(key) }
+ end
+
+ def [](key)
+ with_lock { @storage[key] }
+ end
+
+ def []=(key, value)
+ with_lock { @storage[key] = value }
+ end
+
+ def delete(key)
+ with_lock { @storage.delete(key) }
+ end
+
+ private
+
+ def with_lock
+ @mutex.synchronize do
+ yield
+ end
+ end
+end