From bc0c83691a74ca85768bd5ab488c3184319ca51a Mon Sep 17 00:00:00 2001 From: Maciej Mensfeld Date: Sun, 20 Nov 2022 21:00:44 +0100 Subject: [PATCH] Make the state hash fully thread safe Fixes issue described here: https://github.com/ruby-concurrency/concurrent-ruby/issues/970 --- lib/finite_machine/hooks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/finite_machine/hooks.rb b/lib/finite_machine/hooks.rb index 5007671..26732e5 100644 --- a/lib/finite_machine/hooks.rb +++ b/lib/finite_machine/hooks.rb @@ -18,7 +18,7 @@ class Hooks def initialize @hooks_map = Concurrent::Map.new do |events_hash, hook_event| events_hash[hook_event] = Concurrent::Map.new do |state_hash, name| - state_hash[name] = [] + state_hash.compute_if_absent(name) { [] } end end end