Skip to content

Commit

Permalink
Fix ClientInstanceStream race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hoontee committed Nov 16, 2024
1 parent ae9c5b6 commit 1f38b46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions Pronghorn/New.luau
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,18 @@ function New.ClientInstanceStream(uid: string): (Event<...any>, Event<any>, Inst
local finishedEvent: Event<...Instance> = New.QueuedEvent("InstanceStream Finished Event")
local streamEvent: Event<Instance> = New.QueuedEvent("InstanceStream Stream Event")

container.Destroying:Once(function()
local function checkFinished(): boolean
if #instances == numInstances then
finishedEvent:Fire(table.unpack(instances))
finishedEvent:DisconnectAll()
streamEvent:DisconnectAll()
container:FireServer()
return true
end
return false
end

container.Destroying:Once(function(): ()
finishedEvent:DisconnectAll()
streamEvent:DisconnectAll()
end)
Expand All @@ -486,30 +497,21 @@ function New.ClientInstanceStream(uid: string): (Event<...any>, Event<any>, Inst
table.insert(instances, child.Value)
streamEvent:Fire(child.Value)
else
child.Changed:Once(function()
child.Changed:Once(function(): ()
assert(child.Value)
table.insert(instances, child.Value)
streamEvent:Fire(child.Value)
checkFinished()
end)
end
end

if #container:GetChildren() == numInstances then
finishedEvent:Fire(table.unpack(instances))
finishedEvent:DisconnectAll()
streamEvent:DisconnectAll()
container:FireServer()
else
container.ChildAdded:Connect(function(child: Instance)
if not checkFinished() then
container.ChildAdded:Connect(function(child: Instance): ()
assert(child:IsA("ObjectValue") and (child.Value or child.Changed:Wait() and child.Value))
table.insert(instances, child.Value)
streamEvent:Fire(child)
if #container:GetChildren() == numInstances then
finishedEvent:Fire(table.unpack(instances))
finishedEvent:DisconnectAll()
streamEvent:DisconnectAll()
container:FireServer()
end
checkFinished()
end)
end

Expand Down
2 changes: 1 addition & 1 deletion Pronghorn/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
║ ██████▀██▓▌▀▌ ▄ ▄▓▌▐▓█▌ ║
║ ║
║ ║
║ Pronghorn Framework Rev. B77
║ Pronghorn Framework Rev. B78
║ https://github.com/Iron-Stag-Games/Pronghorn ║
║ GNU Lesser General Public License v2.1 ║
║ ║
Expand Down

0 comments on commit 1f38b46

Please sign in to comment.