99
1010final class StateService implements StateServiceInterface
1111{
12- private const RANDOM_BYTES = 4 ;
12+ private const RANDOM_BYTES = 3 ;
1313
1414 /**
1515 * Keeps the state of balance
@@ -52,6 +52,7 @@ public function multiFork(array $uuids, callable $value): void
5252 ];
5353
5454 foreach ($ uuids as $ uuid ) {
55+ $ values [self ::PREFIX_STATE . $ uuid ] = null ;
5556 $ values [self ::PREFIX_FORK_ID . $ uuid ] = $ forkId ;
5657 }
5758
@@ -76,17 +77,20 @@ public function get(string $uuid): ?string
7677 return null ;
7778 }
7879
79- $ results = $ callable ();
8080 $ insertValues = [];
81- foreach ($ results as $ id => $ value ) {
82- $ insertValues [self ::PREFIX_STATE . $ id ] = $ value ;
81+ $ results = $ callable ();
82+ foreach ($ results as $ rUuid => $ rValue ) {
83+ $ insertValues [self ::PREFIX_STATE . $ rUuid ] = $ rValue ;
8384 }
8485
86+ // set new values
87+ $ this ->store ->setMultiple ($ insertValues );
88+
8589 /** @var array<string> $uuids */
8690 $ uuids = $ this ->store ->pull (self ::PREFIX_HASHMAP . $ forkId , []);
8791 $ deleteKeys = array_map (static fn (string $ uuid ) => self ::PREFIX_FORK_ID . $ uuid , $ uuids );
8892
89- $ this -> store -> setMultiple ( $ insertValues );
93+ // delete callables by uuids
9094 $ this ->store ->deleteMultiple ($ deleteKeys );
9195
9296 return $ results [$ uuid ] ?? null ;
0 commit comments