redis-semaphore 0.2.3 → 0.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmRjZDI2ZDcyOWE2MWM2ZjMwZDA4NjI4YmUwNjVhZjk2MzQ5OWU0Mg==
4
+ NThjZDI5NWY4MjY4Zjc2OWU3ODgxMTUwYjM1NDMyNjEyNjU0ZmY3YQ==
5
5
  data.tar.gz: !binary |-
6
- Yjc5ZDg1MjM0MThkMTcyMDJiYjU5MThhY2JiOWExODdlMjZiMTVkYg==
6
+ MTMzNTlhMjUxZjY3Mzg2ZDAzNWQwMjgxNGUxYzUzNDQ5NTFlMDA3YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmUxYmNjOWFhYTg3OGE4OWI2ZTZkMDM5OTcxMGI1OWY5MjcwZGY2M2ZmYzI3
10
- N2RjMGFmMWQ3NmM2OTYyOGIyZTA2ZWJkMDc1MzlkYmU2MDc2YWUzOThhMDhm
11
- YWUzNmY3MmU2MWM5YTBmY2UwYzFlOWIxNWRkMmJlZGVmMWJkZjQ=
9
+ MTRiMjNkYTdlYWQ3OTkxY2MwYTI0NjIyNzcyM2U0NjQ3MTRhNWRhM2VmNDNk
10
+ MDJkZDUzODE5NWQ5ZjE4YWM0NmVhMzNjMDllOTZiMGFlNjA5YWJjNmMwNWVl
11
+ Yjk2NTVjN2IzYjUxN2QzZTA3MjBmYmZjMzk2YWFlODViZmYyNjA=
12
12
  data.tar.gz: !binary |-
13
- YzQzOTQ2ODJjMjJhYzI1MzJlZWQ5YjYxMTIyMjg5ZTgwZjk4N2M0N2I3OGQ4
14
- ZGEwMTFhZDMyODU3NTEzY2I3OGI0Njk4YzI5ZTg1OTdjMTI1MmEzNDIyNWMw
15
- NmZhOWUwZDg4NGJjZWZmZDNiYWIzNWI5YzkwMzQyOWZkZTFmMDI=
13
+ YzdmYjMzMzlhMDZjZGZjNTVjZGUwNWRlMTk4N2EzYTlkZWFkMjU5ZWIzY2I1
14
+ ZGVlYjM1N2QwYzg3YTFiMDFkYzE3YzM0YTY2OGJmYTgzYTI3Njg0YjEzYmY2
15
+ YTQ5ZDQ2YjY3MWRjNjIzZmIyYmNlMDNkMDQ5OWM0MmNjNzhmNjQ=
@@ -54,16 +54,17 @@ class Redis
54
54
  current_token = token_pair[1]
55
55
  @tokens.push(current_token)
56
56
  @redis.hset(grabbed_key, current_token, current_time.to_f)
57
-
57
+ return_value = current_token
58
+
58
59
  if block_given?
59
60
  begin
60
- yield current_token
61
+ return_value = yield current_token
61
62
  ensure
62
63
  signal(current_token)
63
64
  end
64
65
  end
65
66
 
66
- current_token
67
+ return_value
67
68
  end
68
69
  alias_method :wait, :lock
69
70
 
@@ -95,6 +95,23 @@ describe "redis" do
95
95
 
96
96
  expect(semaphore.locked?).to eq(false)
97
97
  end
98
+
99
+ it "should return the value of the block if block-style locking is used" do
100
+ block_value = semaphore.lock(1) do
101
+ 42
102
+ end
103
+ expect(block_value).to eq(42)
104
+ end
105
+
106
+ it "can return the passed in token to replicate old behaviour" do
107
+ lock_token = semaphore.lock(1)
108
+ semaphore.unlock()
109
+
110
+ block_value = semaphore.lock(1) do |token|
111
+ token
112
+ end
113
+ expect(block_value).to eq(lock_token)
114
+ end
98
115
  end
99
116
 
100
117
  describe "semaphore without staleness checking" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-semaphore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Verhasselt