multi_op_queue 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multi_op_queue/version.rb +1 -1
- data/lib/multi_op_queue.rb +18 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef55a4124c3c6e194ed0bfb384a1e8f6544c9671
|
4
|
+
data.tar.gz: 455219fe3fd38645190290add52e0fdcc61fb48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fc3d578c73a4d68a8bba00f9bc6838bdfbd281743140d1d9e4b5a80946f7393ba660cb602923ef10b7f5d4f3e1e8330517dc5318ddfee0a61f860919b96b08
|
7
|
+
data.tar.gz: 1b39214e29bfc75e55be0f67a15264622a18d367e5f4551a765f85ee3768c70307656c776583db29db085493b1fe06aef1f2c602b9f812f0282ab1ef075f6b76
|
data/lib/multi_op_queue.rb
CHANGED
@@ -47,7 +47,7 @@ module MultiOpQueue
|
|
47
47
|
# Concatenates +ary+ onto the queue.
|
48
48
|
#
|
49
49
|
def concat(ary)
|
50
|
-
|
50
|
+
handle_interrupt do
|
51
51
|
@mutex.synchronize do
|
52
52
|
@que.concat ary
|
53
53
|
@cond.signal
|
@@ -59,7 +59,7 @@ module MultiOpQueue
|
|
59
59
|
# Pushes +obj+ to the queue.
|
60
60
|
#
|
61
61
|
def push(obj)
|
62
|
-
|
62
|
+
handle_interrupt do
|
63
63
|
@mutex.synchronize do
|
64
64
|
@que.push obj
|
65
65
|
@cond.signal
|
@@ -83,7 +83,7 @@ module MultiOpQueue
|
|
83
83
|
# thread isn't suspended, and an exception is raised.
|
84
84
|
#
|
85
85
|
def pop(non_block=false)
|
86
|
-
|
86
|
+
handle_interrupt do
|
87
87
|
@mutex.synchronize do
|
88
88
|
while true
|
89
89
|
if @que.empty?
|
@@ -123,7 +123,7 @@ module MultiOpQueue
|
|
123
123
|
# thread isn't suspended, and an exception is raised.
|
124
124
|
#
|
125
125
|
def pop_up_to(num_to_pop = 1, non_block=false)
|
126
|
-
|
126
|
+
handle_interrupt do
|
127
127
|
@mutex.synchronize do
|
128
128
|
while true
|
129
129
|
if @que.empty?
|
@@ -177,5 +177,19 @@ module MultiOpQueue
|
|
177
177
|
def num_waiting
|
178
178
|
@num_waiting
|
179
179
|
end
|
180
|
+
|
181
|
+
private
|
182
|
+
|
183
|
+
def handle_interrupt
|
184
|
+
@handle_interrupt = Thread.respond_to?(:handle_interrupt) if @handle_interrupt.nil?
|
185
|
+
|
186
|
+
if @handle_interrupt
|
187
|
+
Thread.handle_interrupt(StandardError => :on_blocking) do
|
188
|
+
yield
|
189
|
+
end
|
190
|
+
else
|
191
|
+
yield
|
192
|
+
end
|
193
|
+
end
|
180
194
|
end
|
181
195
|
end
|