Skip to content

Commit 0dbe561

Browse files
authored
fix: ensure that handlers are emptied after notify_all (#501)
1 parent f97a076 commit 0dbe561

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lua/plenary/async/control.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function Condvar:notify_all()
3232
callback()
3333
end
3434

35-
for i = 1, len do
35+
for _ = 1, len do
3636
-- table.remove will ensure that indexes are correct and make "ipairs" safe,
3737
-- which is not the case for "self.handles[i] = nil"
38-
table.remove(self.handles, i)
38+
table.remove(self.handles)
3939
end
4040
end
4141

tests/plenary/async/condvar_spec.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,34 @@ describe("condvar", function()
125125

126126
eq(3, counter)
127127
end)
128+
129+
a.it("notify all works multiple times", function()
130+
local condvar = Condvar.new()
131+
local counter = 0
132+
133+
a.run(function()
134+
condvar:wait()
135+
counter = counter + 1
136+
end)
137+
138+
a.run(function()
139+
condvar:wait()
140+
counter = counter + 1
141+
end)
142+
143+
eq(0, counter)
144+
145+
condvar:notify_all()
146+
147+
eq(2, counter)
148+
149+
a.run(function()
150+
condvar:wait()
151+
counter = 0
152+
end)
153+
154+
condvar:notify_all()
155+
156+
eq(0, counter)
157+
end)
128158
end)

0 commit comments

Comments
 (0)