peplum 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/peplum/application/services/shared_hash.rb +6 -21
- data/lib/peplum/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cf68ae5865f247eefd32f97a3171b4306fdf421a8e73df30429d4ee91c32232
|
4
|
+
data.tar.gz: d26d484ab649e0258ab2855ac81e14db8dbbb9a06509cf00a5d4b957b188ce6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18d05dda4ecd556ba03556dae0754a5c4e085cb90c9f77536abc5156147529b941a9377d3bdf9cfe2b124f0dae4a6cb403d1315190a0a9b0817ab16130c7b383
|
7
|
+
data.tar.gz: 58438b5a98f06d5353cbb4ffa5b9f65b15c7d51401a40498af6f82c9c09a4483e04b6bc78ddeda8427bab930c7402e720015c757d490494876877767c019d5a6
|
@@ -5,49 +5,38 @@ module Services
|
|
5
5
|
class SharedHash
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@hash
|
9
|
-
@sync_counter = 0
|
8
|
+
@hash = {}
|
10
9
|
end
|
11
10
|
|
12
11
|
def get( k )
|
13
12
|
@hash[k]
|
14
13
|
end
|
15
14
|
|
16
|
-
def set( k, v, broadcast = true
|
17
|
-
if @hash[k] == v
|
18
|
-
block.call if block_given?
|
19
|
-
return
|
20
|
-
end
|
15
|
+
def set( k, v, broadcast = true )
|
16
|
+
return if @hash[k] == v
|
21
17
|
|
22
18
|
@hash[k] = v
|
23
19
|
|
24
20
|
if broadcast
|
25
21
|
each_peer do |peer|
|
26
|
-
|
27
|
-
peer.shared_hash.set( k, v, false ) { @sync_counter -= 1 }
|
22
|
+
peer.shared_hash.set( k, v, false )
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
31
|
-
block.call if block_given?
|
32
26
|
nil
|
33
27
|
end
|
34
28
|
|
35
29
|
def delete( k, broadcast = true )
|
36
|
-
if !@hash.include? k
|
37
|
-
block.call if block_given?
|
38
|
-
return
|
39
|
-
end
|
30
|
+
return if !@hash.include? k
|
40
31
|
|
41
32
|
@hash.delete( k )
|
42
33
|
|
43
34
|
if broadcast
|
44
35
|
each_peer do |_, peer|
|
45
|
-
|
46
|
-
peer.shared_hash.delete( k, false ) { @sync_counter -= 1 }
|
36
|
+
peer.shared_hash.delete( k, false )
|
47
37
|
end
|
48
38
|
end
|
49
39
|
|
50
|
-
block.call if block_given?
|
51
40
|
nil
|
52
41
|
end
|
53
42
|
|
@@ -55,10 +44,6 @@ class SharedHash
|
|
55
44
|
@hash.dup
|
56
45
|
end
|
57
46
|
|
58
|
-
def sync
|
59
|
-
sleep 0.1 while @sync_counter != 0
|
60
|
-
end
|
61
|
-
|
62
47
|
private
|
63
48
|
|
64
49
|
def each_peer( &block )
|
data/lib/peplum/version.rb
CHANGED