File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,14 @@ def set
47
47
true
48
48
end
49
49
50
+ def try?
51
+ @mutex . synchronize do
52
+ return false if @set
53
+ @set = true
54
+ @condition . broadcast
55
+ end
56
+ end
57
+
50
58
# Reset a previously set event back to the `unset` state.
51
59
# Has no effect if the `Event` has not yet been set.
52
60
#
Original file line number Diff line number Diff line change @@ -21,15 +21,13 @@ module Concurrent
21
21
end
22
22
23
23
it 'returns false if the event is unset' do
24
- #subject.reset
25
24
subject . should_not be_set
26
25
end
27
26
end
28
27
29
28
context '#set' do
30
29
31
30
it 'triggers the event' do
32
- #subject.reset
33
31
@expected = false
34
32
Thread . new { subject . wait ; @expected = true }
35
33
sleep ( 0.1 )
@@ -44,13 +42,22 @@ module Concurrent
44
42
end
45
43
end
46
44
45
+ context '#try?' do
46
+
47
+ it 'triggers the event if not already set'
48
+
49
+ it 'returns true if not previously set'
50
+
51
+ it 'returns false if previously set'
52
+ end
53
+
47
54
context '#reset' do
48
55
49
56
it 'does not change the state of an unset event' do
50
57
subject . reset
51
58
subject . should_not be_set
52
59
end
53
-
60
+
54
61
it 'does not trigger an unset event' do
55
62
@expected = false
56
63
Thread . new { subject . wait ; @expected = true }
You can’t perform that action at this time.
0 commit comments