File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ def resume
6363 @paused = false
6464 @latch . release
6565 end
66-
66+
6767 def shutdown
6868 @should_shutdown = true
6969 end
Original file line number Diff line number Diff line change @@ -14,6 +14,19 @@ def run
1414 end
1515 end
1616
17+ class Resumer
18+ LATCHES = { }
19+
20+ def initialize ( latch )
21+ @latch_id = latch . object_id
22+ LATCHES [ @latch_id ] = latch
23+ end
24+
25+ def run
26+ LATCHES [ @latch_id ] . release
27+ end
28+ end
29+
1730 before do
1831 Actionable . ran . clear
1932 end
@@ -59,17 +72,19 @@ def run
5972 q . pop until q . empty?
6073
6174 c = Consumer . new ( q , 1 )
75+ consumed = Consumer ::Latch . new
6276
6377 c . pause
6478 t = Thread . new { c . consume }
65- # wait until queue blocks
66- sleep 1
79+ Thread . pass until c . paused?
6780
68- q << Actionable . new
81+ # A job that unblocks the main thread
82+ q << Resumer . new ( consumed )
6983 c . resume
70- # wait until queue blocks
71- Thread . pass until t . status != "sleep"
72- sleep 1
84+
85+ # wait until consumed
86+ consumed . await
87+
7388 assert_equal 0 , q . length , 'all jobs should be consumed'
7489 t . kill
7590 end
You can’t perform that action at this time.
0 commit comments