From deaa72b624462e3dcdae45bd1dcfd0ef1c1df8c9 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 15 Nov 2018 13:15:41 +0100 Subject: [PATCH] use concurrent/map as a thread_safe replacement --- has-guarded-handlers.gemspec | 2 +- lib/has_guarded_handlers.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/has-guarded-handlers.gemspec b/has-guarded-handlers.gemspec index baa6da7..43b2650 100644 --- a/has-guarded-handlers.gemspec +++ b/has-guarded-handlers.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency 'thread_safe', [">= 0.3.4"] + s.add_dependency 'concurrent-ruby', ["~> 1.0"] s.add_development_dependency 'bundler', ["~> 1.0"] s.add_development_dependency 'rspec', ["~> 3.0"] diff --git a/lib/has_guarded_handlers.rb b/lib/has_guarded_handlers.rb index dad0d99..b81bc0f 100644 --- a/lib/has_guarded_handlers.rb +++ b/lib/has_guarded_handlers.rb @@ -1,6 +1,6 @@ require "has_guarded_handlers/version" require 'securerandom' -require 'thread_safe' +require 'concurrent/map' # # HasGuardedHandlers allows an object's API to provide flexible handler registration, storage and matching to arbitrary events. @@ -234,8 +234,8 @@ def check_guards(guards) # :nodoc: end def guarded_handlers - @handlers ||= ThreadSafe::Cache.new do |handlers, key| - handlers.fetch_or_store(key, ThreadSafe::Cache.new { |h, k| h.fetch_or_store(k, []) }) + @handlers ||= Concurrent::Map.new do |handlers, key| + handlers.fetch_or_store(key, Concurrent::Map.new { |h, k| h.fetch_or_store(k, []) }) end end