Skip to content

Commit

Permalink
Merge pull request #157 from ambergamefam/main
Browse files Browse the repository at this point in the history
(Fix) ClientRemoteProperty doesn't update in edge case
  • Loading branch information
Sleitnick authored Sep 25, 2023
2 parents b91a47d + 8eeee4f commit 9327dd0
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions modules/comm/Client/ClientRemoteProperty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ function ClientRemoteProperty.new(
self._ready = false
self._value = nil
self.Changed = Signal.new()
self._readyPromise = self:OnReady():andThen(function()
self._readyPromise = nil
self.Changed:Fire(self._value)
self._changed = self._rs:Connect(function(value)
if value == self._value then
return
end
self._value = value
self.Changed:Fire(value)
end)
end)
self._rs:Fire()

local resolveOnReadyPromise
self._readyPromise = Promise.new(function(resolve)
resolveOnReadyPromise = resolve
end)
self._changed = self._rs:Connect(function(value)
self._value = value
if not self._ready then
self._ready = true
resolveOnReadyPromise(value)
end
self.Changed:Fire(value)
end)

return self
end

Expand Down Expand Up @@ -86,16 +89,7 @@ end
```
]=]
function ClientRemoteProperty:OnReady()
if self._ready then
return Promise.resolve(self._value)
end
return Promise.fromEvent(self._rs, function(value)
self._value = value
self._ready = true
return true
end):andThen(function()
return self._value
end)
return self._readyPromise
end

--[=[
Expand Down Expand Up @@ -137,7 +131,9 @@ end
]=]
function ClientRemoteProperty:Observe(observer: (any) -> ())
if self._ready then
task.defer(observer, self._value)
task.defer(function()
observer(self._value)
end)
end
return self.Changed:Connect(observer)
end
Expand Down

0 comments on commit 9327dd0

Please sign in to comment.