File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def take(timeout = nil)
20
20
@full_condition . wait ( @mutex , timeout ) if empty?
21
21
22
22
# If we timed out we'll still be empty
23
- if not empty ?
23
+ if full ?
24
24
value = @value
25
25
@value = EMPTY
26
26
@empty_condition . signal
@@ -36,7 +36,7 @@ def take(timeout = nil)
36
36
def put ( value , timeout = nil )
37
37
@mutex . synchronize do
38
38
# Unless the value is empty, wait for empty to be signalled
39
- @empty_condition . wait ( @mutex , timeout ) unless empty ?
39
+ @empty_condition . wait ( @mutex , timeout ) if full ?
40
40
41
41
# If we timed out we won't be empty
42
42
if empty?
@@ -53,6 +53,10 @@ def empty?
53
53
@value == EMPTY
54
54
end
55
55
56
+ def full?
57
+ not empty?
58
+ end
59
+
56
60
end
57
61
58
62
end
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ module Concurrent
96
96
97
97
end
98
98
99
- context '#empty' do
99
+ context '#empty? ' do
100
100
101
101
it 'returns true on an empty MVar' do
102
102
m = MVar . new
@@ -110,6 +110,20 @@ module Concurrent
110
110
111
111
end
112
112
113
+ context '#full?' do
114
+
115
+ it 'returns false on an empty MVar' do
116
+ m = MVar . new
117
+ m . should_not be_full
118
+ end
119
+
120
+ it 'returns true on a full MVar' do
121
+ m = MVar . new ( 14 )
122
+ m . should be_full
123
+ end
124
+
125
+ end
126
+
113
127
end
114
128
115
129
end
You can’t perform that action at this time.
0 commit comments