From dddecd590c034c0e99f18bad3e30d182a9dde26b Mon Sep 17 00:00:00 2001 From: Amber Grace <122126644+ambergamefam@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:46:01 -0600 Subject: [PATCH 1/3] Do not drop value updates when multiple updates happen same frame --- modules/comm/Client/ClientRemoteProperty.lua | 38 +++++++++----------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/modules/comm/Client/ClientRemoteProperty.lua b/modules/comm/Client/ClientRemoteProperty.lua index 80d67c94..46d6d963 100644 --- a/modules/comm/Client/ClientRemoteProperty.lua +++ b/modules/comm/Client/ClientRemoteProperty.lua @@ -36,21 +36,26 @@ function ClientRemoteProperty.new( ) local self = setmetatable({}, ClientRemoteProperty) self._rs = ClientRemoteSignal.new(re, inboundMiddleware, outboudMiddleware) + 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 @@ -86,16 +91,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 --[=[ From 39958d137e7955fdc4bce946bcdce3adfb366195 Mon Sep 17 00:00:00 2001 From: Amber Grace <122126644+ambergamefam@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:47:37 -0600 Subject: [PATCH 2/3] Fix ClientRemoteProperty:Observe() race condition --- modules/comm/Client/ClientRemoteProperty.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/comm/Client/ClientRemoteProperty.lua b/modules/comm/Client/ClientRemoteProperty.lua index 46d6d963..88b5b48c 100644 --- a/modules/comm/Client/ClientRemoteProperty.lua +++ b/modules/comm/Client/ClientRemoteProperty.lua @@ -133,7 +133,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 From 8eeee4f10dfe22d43dd8441a44458226773392c0 Mon Sep 17 00:00:00 2001 From: Amber Grace <122126644+ambergamefam@users.noreply.github.com> Date: Fri, 15 Sep 2023 12:53:34 -0600 Subject: [PATCH 3/3] Remove added spacing --- modules/comm/Client/ClientRemoteProperty.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/comm/Client/ClientRemoteProperty.lua b/modules/comm/Client/ClientRemoteProperty.lua index 88b5b48c..b3078c91 100644 --- a/modules/comm/Client/ClientRemoteProperty.lua +++ b/modules/comm/Client/ClientRemoteProperty.lua @@ -36,10 +36,8 @@ function ClientRemoteProperty.new( ) local self = setmetatable({}, ClientRemoteProperty) self._rs = ClientRemoteSignal.new(re, inboundMiddleware, outboudMiddleware) - self._ready = false self._value = nil - self.Changed = Signal.new() self._rs:Fire()